Motorcycle Questions? Ask a Mechanic.
check for a electrical harness in the vicinity of the headlight.
anytime mechanical agitation cases an electrical issue to get better OR worse, it is an indication of a vibration induced problem. either a grounded wire or two or more wires shorted together.
there is no easy way around it. you'll have to start taking things apart until you find the problem and correct it.