While there are numerous detailed answers, this is a brief, simple overview.
1) Moses wrote of what he learned as an Egyptian.
And when he was cast out, Pharaoh’s daughter took him up, and nourished him for her own son. And Moses was learned in all the wisdom of the Egyptians, and was mighty in words and in deeds. Acts 7:21,22
Like every other book in the Word of God, God used the background, education and culture of the author.
2) Moses wrote what God revealed to Him on Mount Sinai.
And Moses wrote all the words of the Lord. Exodus 24:4
God gave part of the Law to Moses directly and Moses wrote down these parts word for word as God dictated them to Moses.
3) Samuel edited the Law. Samuel, the last of the Judges and the first of the prophets founded the sons of the prophets who kept records during the kingdom period.
Then Samuel told the people the manner of the kingdom, and wrote it in a book, and laid it up before the Lord. 1 Samuel 10:25
4) King Manasseh destroyed every copy of the Law he could find. It was restored by King Josiah.
And Hilkiah the high priest said unto Shaphan the scribe, I have found the book of the law in the house of the Lord. And Hilkiah gave the book to Shaphan, and he read it.And Shaphan the scribe came to the king, and brought the king word again, and said, Thy servants have gathered the money that was found in the house, and have delivered it into the hand of them that do the work, that have the oversight of the house of the Lord.And Shaphan the scribe shewed the king, saying, Hilkiah the priest hath delivered me a book. And Shaphan read it before the king. 2 Kings 22:8-10
4) Ezra the Scribe, after the Children of Israel returned from captivity under the Persians, collected the material and edited everything into what we have today.
For Ezra had prepared his heart to seek the law of the Lord, and to do it, and to teach in Israel statutes and judgments. Ezra 7:10
And all the people gathered themselves together as one man into the street that was before the water gate; and they spake unto Ezra the scribe to bring the book of the law of Moses, which the Lord had commanded to Israel. And Ezra the priest brought the law before the congregation both of men and women, and all that could hear with understanding, upon the first day of the seventh month. And he read therein before the street that was before the water gate from the morning until midday, before the men and the women, and those that could understand; and the ears of all the people were attentive unto the book of the law. And Ezra the scribe stood upon a pulpit of wood, which they had made for the purpose; and beside him stood Mattithiah, and Shema, and Anaiah, and Urijah, and Hilkiah, and Maaseiah, on his right hand; and on his left hand, Pedaiah, and Mishael, and Malchiah, and Hashum, and Hashbadana, Zechariah, and Meshullam. And Ezra opened the book in the sight of all the people; (for he was above all the people;) and when he opened it, all the people stood up: Nehemiah 8:1-5
Books were not readily available. To have a book to read from meant that Ezra had to first make (assemble) the parts of the book together.