You have dirty contacts inside the light switch, or a partial ground at the dimmer switch. The headlight switch has a built-in circuit breaker that allows the lights to go out momentarily and then flash back on, rather than blowing a fuse and going out altogether. Inspect the wiring harness from the switch, to the dimmer, to the headlights for bare spots, and you'll probably end up replacing the headlight switch, and possibly the dimmer as well.
Jerry