Headlights go on and off when engine is hot

Do you have a bare wire making a short somewhere. Like bouncing and hitting on and off. Or a bad ground.