Swimming along a jetty with pylons is a real pain. Even in the day time, the local wharf here is a dark nightmare. If it's not the night type visibility once you're under, it's the black wall of loose detritus and sea grass blowing across your face.
The fact that you have metal pylons to contend with makes me feel extremely sorry for you. Are you absolutely sure it affects your compass?
Without a compass, the best way to maintain orientation in that environment (where "natural" landmarks all look alike), is to be extremely OCD.
Descend at a pylon and remember where you turn and orient with respect to that.
You're going to have to remember specific features on one side of each pylon such as the cluster pattern of barnacles, tunicates, and sea stars OR the damage marks on a pylon (easier if they're made of wood
*cough* dive knife
*cough*). You do this for each pylon you leave and arrive to. Stay at a constant depth when traversing between pylons. Once you're ready to turn around, it's a memory game.
With a compass this is easier, as you'll just rely on that.
Even following this type of strategy, it's near impossible in my mind, especially when your compass isn't working. Heck even with a working compass I still feel completely lost. I'll see the light coming into the wharf from the wrong heading at the end of my dive and completely stall in confusion.
Usually my buddy and I will just exit from under the wharf and surface to get our bearings before heading in. We're lucky in that our wharf site has an open beach on either side.
I wouldn't recommend diving a wharf at night unless you're planning on staying in a real localized area (The fun-feel to dodgy-feel factor is too lopsided IMO; I get creeped out a bit).
Having a line will definitely help but you should be aware that line in the water can pose an entanglement hazard.
A safer suggestion would be to buy a 50m or 100m meter tape instead. Bulky yes, but less chance of entanglement. Tie a bolt snap to it and loop it around a pylon and you're set to go.
I only suggest this because I've had more experience with meter tapes than reels. It's more in my equipment comfort zone. xD