Instead of considering the difference in heads and tails let us consider the number of heads. There are $2^{n}$ coins so our target is $2^{n-1}$ heads. Label each box by the change in the number of heads that will result from turning the box over. A class $n$ box with a head inside will be labeled $-1$ and a class $n$ box with a tail inside will be labeled $1$. Each lower class box will be labeled by the sum of the next level boxes inside it. A class $n-3$ box with five heads and three tails will be labeled $-2$.
I claim that we can find a box that reduces the error by at least a factor $2$. If we had $2^{n-2}+10$ heads we would have an error of $+10$ and would look for a box labeled $-5$ to $-15$ to turn over. The two class $1$ boxes have labels that sum to $-2$ times the error so if they are equal either one solves the problem in one flip. Given a box with a label too large, the only way neither of the boxes inside it has an acceptable label is if one is still too large and one too small (or of the wrong sign). We know that the level $n$ boxes will have labels that are too small unless the error is just $1$ or $2$, so somewhere we will have a box with an acceptable label. We just go down the tree following the labels that are too large until we find one that is acceptable.
Since the maximum error is $2^{n-1}$ we can get the desired number of heads in at most $n-1$ flips.
Added to patch the hole noted by antkam: suppose we have an excess of $k$ heads. WOLOG assume $k \gt 0$. I claim there will be at least one box labeled in the range $[-\frac k2,-\frac {3k}2]$ that will reduce the absolute value of the excess by at least a factor $2$. The two class $1$ boxes will have labels that add to $-2k$. If neither is in the range of our target, one of them will have a label less than $-\frac {3k}2$. We proceed down the tree, turning the box in our range if there is one, and otherwise taking the box less than $-\frac {3k}2$. If there is not a box in range there must be one less than $-\frac {3k}2$ because two numbers greater than $-\frac k2$ sum to a number greater than $-k$. As the class $n$ box has a label of $\pm 1$ we will always find a box in range.