The magician already had a ring which housed a genie. While this genie wasn't as powerful as the lamp's genie, he was quite capable of transporting people to anywhere.
Why didn't the magician simply order the ring's genie to transport him near the lamp and then out of the cave?