Verify that the fuses for the headlights are powered, when the lights are turned on. This verifies the light switch and the combo switch. From the fuses the power goes to the Exterior Lamp Failure Module. I would look there and check fot poor solder contacts inside.
Bosch Master, ASE Master, L1
33 years MB technician