וַיִּכְתֹּ֥ב מֹשֶׁ֛ה אֶת־הַשִּׁירָ֥ה הַזֹּ֖את בַּיּ֣וֹם הַה֑וּא וַֽיְלַמְּדָ֖הּ אֶת־בְּנֵ֥י יִשְׂרָאֵֽל׃
So Moses wrote this song the same day, and taught it the children of Israel.
Read kabbalistic (mystical) interpretation of Deuteronomy 31:22: and classical mystical sources.