It sounds like a charging problem. It could be intermittent. A short or an open circuit, only sometimes.
What is the battery voltage when driving with the headlight on? Maybe install a small voltmeter, so you can check it while riding.
_________________
Poul
"If Life Gets Boring, Risk It!"
MC21SE, KISS box
MC21SP, HRC box, racing loom