Some people think that originally Adam wrote it and that it was preserved on the Ark. Interesting idea.
Perhaps it was passed down orally for all those generations. The Jewish people are known for their incredible memorizing capacity. Jewish school children memorize Psalm 119 - the longest Psalm in the Bible.
Prof. R K Harrison’s Intro to the OT argued, if memory serves, that written family histories were available to Moses. The C19 suggestion that Moses could neither read nor write has long been scotched by the evidence available even in those days. He might well have been a librarian in Egypt. And plenty of oral traditions existed, which Moses could, as a poet (so Saint Jerome, & Calvin) & historian, have made good use of under divine inspiration.
Possibly some redaction was done by Joshua (eg re. Moses' death), but the antiquity is well shown by [FONT="]K A Kitchen’s Reliability Of The OT (2003).[/FONT]