Put the bulb in without it being in the headlight housing, rest the bulb on a good safe spot nearby, ensure either high or low beam is activated, (assuming by 'dim' you mean low beam???)
Attempt to wiggle, bend, move-around the wiring harness near the part where it begins to go into the socket, see if it comes on and goes out again. Have a look at the harness connector that leads further up where the whole harness disconnect from the wiring, attempt to remove it, get it under a light, check for that green powdered corrosion look.
Ensure bulb is good, test on other working side for comparison.
Most likely corrosion in either the bulb socket or wiring going to/from harness.
~ Your headlamps being fogged up with condensation on the inside is due to seal not holding out the outside elements, common issue, new headlights or take apart, clear and reseal. Take into house and put near dehumidifier for a day should dry it out on the inside. There is also a black little vent tube on the back of the housing (I thought), ensure it's clear and can breathe.