Thanks a bunch, Paul! (VBG)
I will have to put on my thinking cap and get back to you for further thoughts but here is a beginning. I'm going to attempt this in my usual style which is to try to provide background information and explanation/justification for what I suggest. Some people don't like this and prefer a few word answer but that seems disrespectful. One would order a dog off the sofa but would explain why a human should not sit there.
If you find the long form to be less helpful, let me know & will try to limit to simply questions and answers. The bottom line is to get your headlight working reliably. :-)
1) Is your wiring stock? i.e. Do you have headlight relays, or any other wiring additions/modifications?
2) Are you able to duplicate the symptom now?
3) Will the flashing symptom occur while the bike is stationary?
4) Are both High Beam & Low Beam affected, or both?
5) Will they flash with the bike stationary if you tug, twist, & wiggle the wiring harness?
6) See Note* below in text: Is the headlight the only component affected? It may be necessary to hook up some indicator lights/LED to the City Light for example to see if that flashes also. Ditto Horn Brown is another fairly easy to access check point.
My first "guess-sumption" is that you have an intermittent connection which is being disturbed by the shifting because the only electrical involved in shifting is the Neutral Switch Circuit which isn't active in other than 1st to 2nd. I will outline some wiring information in hope that it will be useful to someone as I've been told that adding this information to a trouble thread often makes the information more usable.
It is usually best, IME, to identify a fault before doing other modifications/improvements because these can sometimes correct or mask the fault and so allow it to remain. It's also a peace of mind thing to correct a headlight problem for certain rather than to hope it won't happen again.
The KLR headlight wiring strategy is, IMO, an odd way to accomplish the task. I've been thinking of modifying the light strategy in order to reduce the chance of headlight function being lost due to a wiring fault but that's an other question.
As you will know, the headlight is grounded by way of the harness common ground (Black/Yellow) which exposes it to a bunch of potential connection (junction) issues within the harness. I recommend (if not using HID) adding an additional ground to the headlight ground terminal in the headlight plug.
The headlight is powered in this fashion from the battery & VRR positive White wire: White wire is fused from the battery (Main Fuse) which joins the not-fused White wire from the VRR. If the Main Fuse is blown while the bike is running, the White from the VRR will still power the bike mostly normally, until the engine stops then you will have nothing. A really "nice" feature for times such as stalling the engine at night while making a left turn in an intersection....
White wire to Main Wiring Plugs (below the instruments), to Ignition Switch, to Brown wire, back by Brown Wire to Headlight fuse (all the way back to the battery again!), then forward by the Blue/White wire to the Main Wiring Plugs under the instruments, then to the Left Handlebar Switch, back to the Main Wiring Plugs under the instruments and to High or Low Beam in the Headlight Plug, then to the common ground (Black/Yellow).
Note* you didn't state that the headlight was the only component losing power.
So, assuming it's only the Low Beam, one would limit the diagnosis to the Red/Yellow wire and High/Low Beam Switch.
Let's await the answers to the questions and then move on.
How are we doing so far?
i'll only suggest, that is a 'puzzle' for Normk!