It could be a number of things. The plug or the connector could be a problem. Wires could be loose in the junction box in the pin box. Since your rig has had some use it could also be the wiring going to the brakes. Over the years the rough axles can rub the insulation off.
Dick, Joyce, Diego, Picatso and Gustav
2017 3720 RL, MorRyde pin box
2017 3500 Dodge Maxi DRW 4X4, Pullrite Hitch, IS, Disk Brakes, 3rd AC, Winegard Traveler, Bathroom door mod, Dometic 320, couch for desk swap, etc.