Bad Habits

The best way to stop a bad habit is to get it as it starts - while it's still just a naughty twinkle in their eye. Unfortunately we're not always aware that a habit is forming. I was asked at the Erin Fair what to do when your pony wants to rub its head on you. Awwww, isn't that cute? She's itchy, poor thing. Here, let me scratch that for you. Look at the funny face she makes!
The next week: She wants to rub her head again. Oh, okay. She must be itchy. Jeepers, she's rubbed her bridle off!
Week three: Darned pony, that bridle hurts when she rubs her head on me and it makes it really difficult to get it off her head without clunking her mouth on the bit.
Week four: Now she's started throwing her head when I bridle her because she thinks the bit is evil. Then she got loose when I dropped the bridle on the floor while taking it off. She's almost knocking me over with her exuberant head rubs.
See why I call my pony Snowball? The behaviour quickly snowballs. One thing quickly leads to another, and it doesn't get better unless you make it better. After all, you have created the monster. Now you have to fix it. It's not the pony's fault.
Fixing it, however, takes consistent effort. You have to decide that you don't want this behaviour anymore, but you also need to make a plan to either replace or extinguish it.
How do you stop the head rubbing?
Start by making sure the trigger, for example taking off the bridle, isn't the root of the problem. Is the bridle causing discomfort? Try different bridles and bits and see if the behaviour changes. 
Is the pony bothered by bug bites or sores? Check their hair to see if all is okay.
If you've explored any obvious physical cause, then it comes to behaviour. You will need to make the delicious head scratch not so appealing - take a firm hold of the halter and say 'no', but at this point you don't want to make a big deal of this. That wouldn't be fair, considering you've encouraged it either by scratching back or not discouraging it for so long. It may mean leaving the halter on underneath the bridle and taking a firm hold of it while you're bridling and un-bridling. Whatever you do, don't accept any head scratching whatsoever and don't encourage it at any time, even in the field when you're just hanging out. Insist on some personal space when you're near their head. Be consistent. Don't let her rub on anyone else either!
It will take as long or longer to extinguish or replace a behaviour as it did to perfect it, so if you figure the behaviour has been going on for months, maybe years, before you a) noticed it wasn't desireable, and b) decided you didn't want to put up with it anymore, it makes you realize that it's going to be a long road. Good luck!