Moses compiled the book of Genesis from previously written manuscripts. The first covered Genesis 1:1 to Genesis 2:4. Notice verse 4 says, "This is the history of the heavens and the earth in the time of their being created, in the day that Jehovah God made earth and heaven." In our time, in English, this would be the first verse, but in Hebrew what we would call the 'introduction,' comes last.
2 Timothy 3:16 tells us that God inspired the Scriptures when it says, "all scripture is inspired of God and beneficial for teaching, for reproving, for setting things straight, for disciplining in righteousness, . . ." So Jehovah is the author of the Bible and he determined what would appear in it by guiding his devoted servants. He guided Moses to record what facts it was important for us to know.
Also knowing that Moses used many written scrolls, we can understand that everything in Genesis is not strictly in chronological order.