So, The Doctor had two sonic screwdrivers with him. And he knew he was going to a place where there was an early version of The Flesh. And then he deliberately waved his hands over it and used the sonic on it. So he basically caused a second version of himself to be made, and then armed it with a sonic screwdriver.
A sonic screwdriver that, if you recall Forest Of The Dead, can be used to store personalities in its neural relay. Which goes some way to explain why Mr Smith said "There may be a way back from this." just before activating it.
All of which leads me to the theory that the Doctor that we see in the first episode of this season, is not The Doctor, but the Flesh version of him, reconstituted from the memories stored in the neural relay.
Original post on Dreamwidth - there are comments there.