its called EMI, electromagnetic interference.
the headlight is LED. it probably has a "3 click" switch, once bright, twice, dimmer, 3 times, off... or similar
that requires a digital circuit internally. 99% of LED circuits have some kind of digital nonsense inside, as an LED lights instantly, and by "pulsing" the power supply, they can be very efficient! being on for only a 1/4 of the time, taking full battery current, rather than being on 100% of the time, requiring a resistor to reduce current through LED, which just wastes battery power as heat in the resistor.
the spark creates interference that messes with the digital circuit in headlight.
possible cures...
1, use ngk BR*** spark plug series, they have an internal resistor.
2, use silicon "auto" plug wire, also contains resistor...
3, get resistive spark plug cap/boot...
(use of resistor reduces or "suppresses" EMI)
4, wrap headlight in foil, make sure one part is in contact with earth or bike frame.... electrostatic shielding!
5, wrap CDI unit in foil... same deal!
6, place headlight AWAY from ignition systems!