I had the same problem with the flickering on and off on my XJ, It was a loose connection on the 40 amp Maxi-Fuse in the fuse/relay panel under the hood.
I took out ALL fuses and relays and cleaned the contacts, and applied dielectric grease to all connections.
I did clean that connection to the headlights under the airbox when I removed the front end to do my homebrew fix for the sagging driver door. That connection does get dirty.
[B]His: 2006 Bright Silver Commander[/B]
[B]Hers: 2004 Bright Silver Grand Cherokee Laredo[/B]