Good that your light is working again!.
One thing that can happen is that dust finds its way into the contact points. Another less common thing is a crack in the circuit traces of the circuit board. Poorly soldered parts are also common especially with highly discounted Chinese merchandise.
Speaking of highly discounted Chinese merchandise, I just bought an LED goose neck light called a "sewing machine light" for $10 on Amazon. It works excellent (very bright and perfect for a scroll saw) but I discovered that when the base gets in close proximity of a strong magnet (like my 1" cube rare earth magnet), the LED light fails.. I am thinking that the on/off switch must have a metal part that bends away from its contacts when it gets close to a strong rare earth magnet. I suppose the inductance of the inductor in the switching power supply might go wonky in the presence of a super strong magnetic field. Who knows? Lol!