Weird problems like this are usually bad grounding.
I presume your front lights are grounded up front to the chassis near the lights themselves....that is how my Export 2002 CRD lights work but there are differences between the USA and Export models as far as the lighting goes. Always worth cleaning up and tightening the grounding points.
If you physically remove the front lamps and go through the same procedure do things change?
Could be the Multifunction Switch or the High and Low Beam relays on the interior fuse panel (PDC)...high beam relay is the only relay on the front side where the fuses sit..the Low Beam Relay is one of the relays on the reverse side. I do not have Wiring Diagrams for the 2004 KJ so cannot tell you where the low beam relay actually is located.
If things work fine with the front bulbs removed...other than no light coming out up front...you should be able to bypass the circuitry for the front bulbs by fitting 4 relays right at the front bulbs...one for high beam left side, one for low beam left side and same on the right side. Then the leads that normally go to the bulb filaments you connect to power up the relays....you pass +12 volts from the battery through the relay contacts via an inline fuse.
I did the above when I upgraded my bulbs from 65 w to 100 w to get better lighting and did not want to pass too much current through the existing relays. Pulled this off when 100 w bulbs got banned here.
You can download the Jeep KJ Service Manual here...wiring diagrams are in section 8W.
The 2004 models are not listed so you can try the 2003 or 2005 models but wiring colors will probably be different.
You need to make use of a multi meter to trace that +12 volts is always where you expect it to be with respect to chassis. Also check that the fuses relevant to the lighting circuits are in tight...re-plug them to make good contact.
KJ Service Manuals:
Index of /manuals/Jeep/KJ