I had a headlight that would go dim and sometimes go out. I cleaned all the grounds and thought I had it fixed but finally figured out that it was the headlight socket. It was worn or broken inside and the wires would touch. Soldered a new one on and no more problems.
Scott