Millennium Man was written for several reasons. Firstly, I wanted to explore the idea of Time Lord rituals. There has always been the idea of a ritualistic society. We had some clues about it in episodes such as Deadly Assassin and Invasion of Time which both featured ceremonies in the Panopticon. Deadly Assassin also featured some surreal explorations of unreal worlds within the matrix. I also wanted to look at the way The Doctor still wanted to maintain the traditions of his lost world. He sticks by the laws of Time. He remembers the rituals, wanting to marry Rose in the correct way. The Rite of Progression is one he was not expecting, but he faces it manfully, as he faces everything that is thrown at him.
Da Mo, is the founder of Shaolin Gung Fu. He developed the moves used in the martial arts to keep his limbs and muscles active during his nine years meditation. So the legends of Shaolin have it, anyway.
The ordeal he goes through on the Plain of Attrition owes something to other sources. Particularly, it is a lot like the place where Omnians go after death in the Terry Pratchett Discworld novels. The stepping backwards into the light scene is very much a homage to Discworld. There, it was Granny Weatherwax the witch who was challenged to decide whether to walk in the darkness or the light. She, like The Doctor, knows that the choice is never so clear cut, and that the grey is where people who fight against the darkness have to walk. It seemed right to have him make the same choice.
The Sword of Lœngbaerrow was a piece of made up mythology. But one that fitted. The Doctor needed a sword in this story and why not make it one that was special to him.
Meanwhile, in the real world, there are two TARDISes on SangC’lune, because Ten is the same age as Nine and he has his Rite of Progression, too. The companion story from his point of view is in the Ten series of stories, where he had a similar but different experience on the Plain.
And of course, that sets everyone up nicely for a couple of two Doctor episodes where Nine and Ten works together.