I had similar problems with front indicators/running lights, if not the headlight, and it was all due to bad connectors. Specifically, some bullet connectors under the front fairing. I live a humid climate, and I often end up riding in the rain, and I noticed the problem usually occurred in the damp times, though jostling could trigger it. To my eye, the connectors didn't look bad, only very slightly corroded, but they were the problem. .I tried cleaning up the connectors and using grease, but the problem kept returning. In the end I just got better connectors, and that fixed it.