The first five books of the Old Testament are attributed to Moses, who would have gathered together records by Adam, Noah, Shem and Abraham which had been passed on by word of mouth, or possibly in some more permanent form. He added the account of the history of Israel and the laws that God commanded him to write.
When the Israelites returned from exile in Babylon the preservation of God’s word was important for them. Ezra and Nehemiah are credited with collecting the existing writings together. Ezra read to the people from the Book of the Law of Moses (Nehemiah 8:1), and a non-inspired writing, 2 Maccabees 2:13, says, “Nehemiah collected the chronicles of the kings, the writings of prophets, the works of David, and royal letters about sacred writings, to found his library.” These writings would have been in the form of scrolls.
In the time of Jesus, the Hebrew Old Testament consisted of 22 books, as it does today. These are exactly the same as our 39 books, but grouped differently, e.g. the 12 minor prophets are grouped together in one book. It was a Jewish tradition that nothing should be added to or taken from this Old Testament. This Old Testament was endorsed by Jesus as being the word of God and when there are references in the New Testament to the Scriptures this is what is meant.
To a large extent the Apostles determined what was recognized as New Testament Scripture and what was not, and there seems to be general agreement among the early churches. Collections of the New Testament writings began to be made in the second century AD. Emperor Constantine commissioned Eusebius to provide Bibles for use in churches, and in 367 AD Athanasius of Alexandria produced a list of the New Testament books as we know them.