The problem is a bad switch or its connections somewhere within the tail light harness, the up and down motion of the car is causing the harness to make intermittent contact. Start off by examining the light sockets and its wires, look for corrosion and any broken connections then work your way to the switch. Do all of the testing with a DVOM set the meter for continuity and probe the ground side first, if you do get a reading on the meter start wiggling the harness until the break within the circuit happens. Take note of the positioning of your hands in relation to the meter to get a rough estimate of where the break in the wire is, open the harness up and repair it with a new connection using the same wire gage.
" What were dealing with is the battle between the future and the past, between the powers that were and the powers that have yet to be. " --- John Perry Barlow