According to the Ramban, when the Torah says ועתה כתבו לכם את השירה הזאת (לא:ט) it means simply that they should write the Shirat Ha'azinu which follows immediatley. It is called a Shirah because it is written in stanza form and recited as a psalm.
Ramban holds that this commandment was given to Moshe and Yehoshua. This was done because Hashem wanted Yehoshua to become a prophet even before Moshe died. When Moshe later teaches the Shirah to Bnai Yisrael, Yehoshua is at his side helping (לב:מד).
Ha'amek Davar takes a different approach. He is surprised at the Ramban's view that Yehoshua had also been comanded to write the Shirah with Moshe. It was written entirely by Moshe as it says ויכתב משה את השירה הזאת (לא:כב). However, according the the Ha'amek Davar, there is a difference betweeen Moshe's writing of the Torah and writting the Shirah. The Torah Moshe first taught to Bnai Yisrael orally, as Hashem had taught it to him and then he wrote it down. The Shirah was first written and then taught to Bnai Yisrael.
Why is it that regarding the Shirah it was first written then taught orally, whereas the rest of the Torah was taught orally and then written? Perhaps the difference is that the Torah contains laws that Bnai Yisrael needed to know right away. The laws of Kashrut for example were needed as soon as possible. Therefore Moshe first taught the Torah and all its laws first and then wrote them. The Shirah is a song of praise. It contains no laws only praise and glory to Hashem. Bnai Yisrael did not need to know it right away. True they were comanded to know it but it did not need to be known immediately.