Passage
And it shall come to pass, when many evils and troubles are come upon them, that this song shall testify before them as a witness; for it shall not be forgotten out of the mouths of their seed: for I know their imagination which they frame this day, before I have brought them into the land which I sware.
Nearby Context
Deuteronomy 31:19 Now therefore write ye this song for you, and teach thou it the children of Israel: put it in their mouths, that this song may be a witness for me against the children of Israel.
Deuteronomy 31:20 For when I shall have brought them into the land which I sware unto their fathers, flowing with milk and honey, and they shall have eaten and filled themselves, and waxed fat; then will they turn unto other gods, and serve them, and despise me, and break my covenant.
Deuteronomy 31:21 And it shall come to pass, when many evils and troubles are come upon them, that this song shall testify before them as a witness; for it shall not be forgotten out of the mouths of their seed: for I know their imagination which they frame this day, before I have brought them into the land which I sware.
Deuteronomy 31:22 So Moses wrote this song the same day, and taught it the children of Israel.
Deuteronomy 31:23 And he gave Joshua the son of Nun a charge, and said, Be strong and of good courage; for thou shalt bring the children of Israel into the land which I sware unto them: and I will be with thee.
Study Lenses
The verse centers on "shall", "come", "pass", "evils", "troubles", "upon", and "song". It is saying that the verse draws attention to "shall" and "come", so its meaning should be read from those terms before moving to application.
The nearby context moves from verse 20's "For when I shall have brought them..." into verse 22's "So Moses wrote this song the same...", so "shall" and "come" belong inside that flow. In Deuteronomy context, the local focus is covenant, worship, and faithfulness.
A plain takeaway is to answer the verse's own emphasis on "shall" and "come" with trust shaped by these words, not by a vague optimism outside the passage.