1. No one on earth can say "all the grounds are good" regarding electrical problems.
2. The headlights go thru the dimmer. Could be the dimmer. Tail lights don't go thru dimmer, see if they are going off and on. They are on a different terminal on light switch however.
3. Could be a loose wire.
4. Could be the light switch.
5. Could be a corroded connection. Does it do it in high beam and low beam?
6. If you think it is the switch, pull the hot wire off of the dimmer switch and tape it's end. Install a jumper from the battery to that dimmer hot terminal.
If no more trouble, it's the switch or switch wiring. Take off jumper when you get to work or lights will stay on.
If you are not good or careful or knowledgeable with electric, or can't do the jumper, buy a new switch.