If you think about it, the second pasuk is very hard to understand. Why does the Torah need to tell us that Moshe wrote something in the Torah? We know Moshe wrote the Torah, that’s an article of faith:
And secondly, why bother listing all the places they traveled through? The entire previous book of במדבר told us what happened in all the places where something interesting happened; why a list of nearly meaningless place names?
The answer to the first question seems to be a matter of timing. The Torah as a whole was written down at the end of Moshe’s life; this list must have been written as a separate “pamphlet” when בני ישראל arrived at ערבות מואב, before Moshe started his farewell addresses:
But this does not answer the question. Why was it necessary to write down their travels separately from the Torah itself? Rashi on this pasuk brings two explanations.
And the Rambam brings an explanation related to Rashi’s first, that the list teaches us of ה׳'s mercy (though he has a different approach):
Why does Rashi bring two explanations? I think it is because we have two questions: why write this list separately and why write it in the Torah? There are two audiences for the list, them (the people about to enter Israel) and us. The fact that Moshe wrote the journeys out was to distribute to בני ישראל, as a sort of source sheet for the speech he was about to give:
Hence it is like the father reviewing the past with his son as they return home.
The first reason goes with our second question. It is written in the Torah, for posterity, so that we can, in later generation, testify to ה׳'s kindness in supporting us in the winlderness.
After quoting Rashi and Rambam, Ramban adds:
Ramban does not tell us what the סוד that required an explicit command from ה׳ to write this, but the Sfas Emes says something that may give us a hint. In Chassidic fashion, the journey is symbolic of our journey through life:
Rabbi Riskin points out another question on the pasuk: the second half repeats the first half, but reversed: מוצאיהם למסעיהם followed by מסעיהם למוצאיהם. מוצאיהם למסעיהם I understand: Moshe wrote the places they left to go traveling. But what does it mean that they traveled to the places they left? That’s backwards; they traveled from the places they left.
Rabbi Riskin proposes that it is meant as a matter of mindset: they were traveling to the places they had left. They were going back home. In the first Egyptian exile, Avraham did this literally:
And, מעשה אבות סימן לבנים, בני ישראל did the same thing (though not literally) when they left Egypt. And, even more מעשה אבות סימן לבנים, that is how we should view the long journey of the Jewish people over the millenia: