Lets restructure the wording.
Suppose the two boxes are labeled H & T, both with n pencils.
We flip a coin, if it is heads we take one pencil from box H and tails we take one from T; then continue.
If we will calculate the probability that when T is first empty there will be exactly remaining in box H.
Because this is a symmetric problem we will just double that to answer the question.
To have the above setup we need the last flip to be a tail.
Before that we need to have had tails come up and heads to have shown. This is a total of flips occurring in any order. The one more flip on which tails, then box T is empty and box H contains k pencils.
What is the probability of that?
Those tails may occur anywhere among the first flips, then one more tail.
To get either box we double that.