One important element of the way that the gum works is called "context-dependent memory". The following is quoted from the Think Gum website:
One principle this functional gum relies on is called, “context-dependent memory.” This is the idea that if you learn something in the presence of a certain stimuli then when you are in the presence of the same stimuli later, your memory of what you learned will be stoked. A good example of this phenomenon is the aroma of pumpkin pie. The smell makes people happy, relaxed and just plain gushy inside. However, smell doesn’t “do” anything to you. It simply elicits the good thanksgiving memories that are ever so closely linked with the scent of pumpkin pie.
I think this is an excellent explanation to why music and the rhythm in my head coincides with when I'm successfully writing or taking an exam. Because I often study with music I'm building a "memory track" for the studied material and the tunes. Cool, explanation, eh?