Welcome to TRS
I would get a Volt Meter and check battery voltage with engine/key OFF
12.3 to 12.8 volts would be normal
Then start engine
13.6 to 14.9volts would be normal
Voltage is higher just after starting and then gets lower after battery recharges, 13.6 would be minimum voltage with engine running.
I think your charging system is the problem.
When you turn on the head lights the system voltage is dropping too much and spark is effected.
Does the Battery Light come on when you first turn on the key?
It should
And does it go off after starting the engine?
It should
Has it ever flickered at lower or higher RPM?