2005 Dodge Dakota Head lights

I bought this truck new. A few years ago while driving to work my headlights began to flicker. The problem became intermittant and didn’t seem to affect my fog or high beam lights, just low beam. That night I tried to find the loose connection with no luck. The truck had 35000 on it then. To play it safe I went ahead anf replaced the light switch. The next day the problem went away but came back about a year later and again the lights would flicker then stay on for a while and start again. The problem would disappear for a day or two and start again. I put this truck into two Dodge dealerships and they couldn’t find anything. The problem went away for about three weeks and came back. This time I put the truck into a different non-Dodge repair place and after three days they couldn’t find anything after pulling various connections apartbut said the likely cause is probably one of two electronic parts. One was about $300 and the other was just over $500 and they were nonrefundable because they were electronics. I went ahead and went the cheap way. After a little more then a year I noticed my headlights went out for about two seconds and came back on. It didn’t do it anymore that night. Then about a week ago I got about a mile from my house going to work my headlights started flashing as if they were sending “morse code” in 5-10 second bursts. Again, hi beam and white fog lights are unaffected. I’ve since parked it. I’ve looked to see if there were any service bulletins, recalls, etc and found nothing. I’m finding it really hard to believe that my truck is the only one doing this. Any ideas???

What was the “electronic part” they replaced for $300 a year or so ago?

What was the part they wanted $500 for?

The only parts that were replaced during this episode was the headlight switch and the $300 electronic part.