I should make a couple of remarks.
- Heaven (capitalized) is not necessarily the same as heaven (not capitalized). Depending on the context, Heaven usually refers to a heaven from a religious context, for example, Heaven in Christianity. In such a case, Heaven is a proper noun.
- Similarly, God (capitalized) is not necessarily the same as god. Depending on the context, God usually refers to a god from a religious context, for example, God in Abrahamic religions. In such a case, God is a proper noun.
Do we have to write Heaven or heaven when it is not first in the sentence?
It depends. If it is a reference to, for example, the Christian one, it appears that you can choose to capitalize it. Even the Christian bible has an instance in which it is not capitalized. As for the reference to the Chicago Manual of Style
8.108 Heaven, hell, and so on
Terms for divine dwelling places, ideal states, places of divine punishment, and the like are usually lowercased (though they are often capitalized in a purely religious context)
So if your audience understands that you are writing in a religious context, then you are free to capitalize it.
If it is a generic or secular heaven and not a proper noun, then it should be written as heaven.
Returning to the lyrics, I understood them to be
Couldn't keep it in
Heaven knows I tried
with the line break and without the period. While writing a post, people often hit enter/return for a line break, but the line break doesn't display. So, I assumed that's what OP meant to display. It makes sense that there are no punctuation marks since lyrics found online are generally poorly written and often omit proper punctuation. Having it displayed this way, "Heaven" is at the beginning and should be capitalized.
If the word "H/heaven" is found elsewhere in the sentence, like at this site
Couldn't keep it in, heaven knows I tried!
then I believe it should not be capitalized, for the reason I give below.
Does "Heaven" have the same meaning as god here?
I assume you meant God (for example, in the Christian sense). Since this is a Disney movie and Disney does not produce religiously affiliated material, heaven would be a secular term and not a proper noun. Since we are speaking of heaven in a secular sense, then no, heaven does not mean the same thing as God. However, the expression is still understood to have the same meaning as "God knows".
Now, if it was, for example, a Christian person writing and chose to write Heaven instead of heaven, then yes, it is possible that Heaven meant the same thing as God. Heaven is often a euphemism or allusion to God in Christianity. So one could say that, in such an instance, Heaven meant the same thing as God. Further, "Heaven knows" would also mean the same thing as "God knows".