If that happens the same way every time you have a very unusual situation.
Does it happen the same way every time ?
Can you tell us if the bike has a relay fitted to power the headlights, (being a 07 there is a big chance it has been done).
Does anything change when you apply front or rear brakes ?
Do the brake light & tail light work with the headlight on or off ?
First thing you should check is your battery terminals are clean and tight, they do work loose on bikes very easily and unlike a car it may not stop the bike from starting.
Some of the 19 rides in my shed
2014 V2, Snoopy
2009 Wee, Pumbaa the pig
WR450F, The Blue Postie Bike
YZ250N smoker with rego, Stinky.
Yamaha MT09 (FZ09), The Scud missile.
Club Lead not Club Med.
He with the most toys wins.
Out of my depth in a puddle.
Live life on the edge you will see more that way.
Ridding a motorcycle keeps things in balance.
At the end of each trail and at the end of each day history is made.