How did Moses write the events which happened ~2000 years before him?
This is a great question, and one might have thought that we have nothing at all to go on, except guesswork. But actually we do have something to go on, and that is the existence of Hebrew words in early Genesis which are loan-words from other languages.
According to Robert D. Wilson, throughout most of the first five books of the Bible the predominant language from which words are loaned is Egyptian.
But there are no Egyptian loanwords in the chapters prior to the descent into Egypt. The loanwords in the first chapters are from Babylonian and Sumerian, suggesting that either Moses simply fully incorporated something already written into Genesis or he summarised something already written - and what he included was something which had been written by an (unknown) author who lived in southern Mesopotamia/modern southern Iraq.
Personally, I think the most likely means, even the only means, by which he could have received these writings was via the Hebrew community, and they received them via Abraham. (Even though Moses would have had access to the libraries of Egypt these would not have contained divine/prophetic literature, or even if they had contained prophetic literature it is still necessary to have a reliable witness to authenticate them. The authenticating witness to these writings in my opinion could only have been the Hebrew people. Furthermore, there must have been a godly line, akin to a prophetic line, all the way from the time the writings were first produced in Mesopotamia down to Moses. It was this godly line which passed from generation to generation the authentication needed for the inspired writings.
For more information on this look at "Foreign words in the Old Testament as an Evidence of Historicity" by Robert Dick Wilson,and scroll down to start reading from page 210.
(The English of) Hebrew words known to be of Babylonian origin are: Adam, Abel, Methusaleh, Amraphel, Chedorlaomer, Tidal, Abram, Sara, Babel, Ur, Erech, Haran, Havilah, Calah, Padan, Ninevah, Eden, Shinar, to cover with pitch, pitch, cherub, oven, to dwell, flood.
(The English of) Hebrew words known to be of Sumerian origin are: Arioch, Gihon, Pishon, Hiddekel, gopher-wood, cereal, canal.
The whole of this work by R.D. Wilson is worth studying but its not an easy read.
Foreign Words in the Old Testament as an Evidence of Historicity by Robert Dick Wilson:- https://biblicalreadercommmunications.files.wordpress.com/2017/01/foreign20words20in20the20ot20as20evidence20of20historicity20192820ptr2026-2.pdf
Another evidence of Mesopotamian Origin of early Genesis
In most countries today I guess that each 24 hour day begins and thus the date and the day-name changes at midnight (24:00 hours or 00:00 hours). The ancients obviously could not choose midnight as the time when the date changed: we would imagine the most obvious time of day for the change would be sunrise, when the first sliver of the sun disk becomes visible. And true enough, for the ancient Egyptians, before and during the time of Moses, a 24 hour day began and the day-name and date changed, at sunrise.
But in Genesis chapter 1 we find that a 24 hour day begins, not as might be expected at sunrise, but at sunset. So we read "and there was evening and morning, the first day" (Genesis 1:5, and 1:8, 13, 19, 23, 31). For each 24 hour day the evening and the night came before the hours of daylight.
However, in all the cultures of Mesopotamia a 24 hour day began at sunset, just as with Genesis chapter 1.
This difference between Egypt and Mesopotamia is all based on the way they calculated the start of the lunar month. In Mesopotamia the lunar month began with the first appearance of the new crescent moon after it had disappeared for a few days at the time of New Moon. Each month, the first appearance of the new crescent moon started the first 24 hour day of each month, lunar day 1.
In all countries the world over the new crescent moon makes its first appearance in the evening. ((So in fact in ancient Mesopotamia the first day of the month the day ended and began not with sunset but with the first appearance of the new crescent moon, near to the time of sunset.)) This meant that each 24 hour day for the remainder of the month would necessarily start at sunset in the evening. I would suggest the Mesopotamian way is really an obvious way of identifying the start of a new month: but it does mean each 24 hour day would thereafter start in the evening.
The Egyptians chose a different way: I suppose you could say they chose to observe what ended the old lunar month (and thus only by extension what started the new month). They observed the disappearance the old crescent moon. Just before the time of New Moon the old crescent moon makes its last appearance of the month in the morning just before sunrise. The day after its last appearance, of course, it disappears. For the ancient Egyptians this disappearance marked the end of the old lunar month and thus the beginning of the new lunar month. And because the last crescent moon appears (everywhere in every country) in the morning sky (before/around sunrise) and the disappearance was noted in the morning sky, so the first lunar 24 hour period, lunar day 1, began in the morning (- which of course had the knock on effect that all the days of the month began in the morning).
If Moses had written Genesis 1:5 based on his own experience of the Egyptian culture in which he grew up he would have written "And there was morning and evening the first day".
Genesis 1:5, 8 etc are a further indication that early Genesis had its origin not from Moses' own experience of ancient Egyptian culture but from Mesopotamia.