The whole transfer of power from Moshe to Yehoshua was intermingled with Moshes writing down the "shira" and the Torah.
In 31:7-9, Moshe calls Yehoshua and gives him a motivational speech (be strong...) and then Moshe writes the Torah.
In 31:14-19, Moshe and Yehoshua get some instructions from Hashem for the passing of the baton, "And now write the shira and teach it to Israel..."
I think the success of the transfer of power was predicated on Moshe being able to show Yehoshua that an integral part of his leadership is remaining true to and incorporating the Torah as a basis for life. It is not just he, Yehoshua, who needs to be powerful and smart and strong, etc in order to lead the nation into Israel. Rather that strength, that leadership comes from the Torah. It comes from Hashem. It comes from leading with the values of the Torah.
Moshe is showing Yehoshua that if his foundation is the Torah, if his every move is based on the Torah, if the Torah is so ingrained in him, then he will be able to lead Israel successfully.