Is there any change when you play with the headlight switch? This is a common wear point and if the connection in the switch is starting to go then you might experience the problem that you’re having, if the lights flicker more or less when you play with the switch I would start by replacing the headlight switch and rechecking for the condition.
Of course check the charging system as mentioned just to be sure that’s in good condition first.