I do this sometimes. Mainly when I've had a "hungry day" and gone to sleep hungry. Or when I have disturbed sleep from too much caffiene near to bedtime.
Is it possible to lock your kitchen door? Or at least close it? Also try to make sure that your sleep is not interupted. Eg last night I was awake because of caffiene and I'd drunk quite a bit before going to sleep so I was up about 3 times for the bathroom. I nibbled a cookie one time, then some dry frosties that were out on the counter. If the cupboards were closed and the food isn't just left out like that, then I think I stand a better chance of not doing it.
But I know that for me, it's when I have interupted sleep that I nibble in the middle of the night.
Try those couple of things, shutting the kitchen and trying to sleep through. Also, it might help if you are snacking on "naughty" things to have that treat before you go to bed, so you KNOW you've had a treat. If you don't want a treat, then how about a glass of skimmed milk? It will keep you feeling full while you're asleep and less likely to be hungry in the middle of the night. I'm more likely to snack on junk in the middle of the night because it "doesn't count"
In fact eating junk at night is the worst for fat storage because you have more insulin in your blood (fat storing horemone) and you are inactive, so it will be unlikely that it's burned off before breakfast!
You could also try to get DH to lock the treat foods away, my Mum used to get Dad to hide the Christmas chocolates so that they weren't all gone before Christmas!
If those things don't work, then perhaps have a talk to your doctor, but I think you should be able to break yourself of this habit if you can figure out your triggers.