The Old Testament Scriptures record the process of collecting its books. From the beginning of the written Law, Moses gave the Law to the priests to care for it (Deut. 31:9). God commanded that the Book of the Law be placed in the Ark of the Covenant for which the Levites oversaw (Deut. 31:9, 26). From Moses on, books were added to the Law as they were written by inspired men. The book of Joshua records Joshua writing in “the Book of the Law of God” and adding his inspired words to the Law of God (Josh. 24:26). Even unto the writing of Chronicles, the Book of Kings was written into the Law of the Lord (2 Chron. 35:26-27), and the Book of Kings reads that the Chronicles were added to the Law of God (2 Kings 23:28).
The Old Testament also records that the Law was preserved through the centuries. Even until the reign of Jehoshaphat, the Law was being taught in all the cities by the prophets and by the Levites (2 Chron. 17:9). The Law was found in the keep of the Levites and read before King Josiah and all Israel before Israel’s captivity (2 Chron. 34:17-21, 2 Kings 22:8-16, 23:2-3, 21-28). Then even further to the time of Israel’s restoration, Ezra is described as a priest and the scribe of the Law of God (Ezra 7:11-12), and he returned from Babylonian captivity and set his heart on the study of the law of the Lord (Ezra 7:10). The Book of Nehemiah also records Ezra as being the scribe of the Law and reading it to the remnant who had returned from captivity (Neh. 8:1). Clearly, the Law was kept and copied throughout the centuries from Moses to Ezra, which is over a millennium. Only prejudice would discount the reliability of the scriptures affirmed by the Septuagint, the Dead Sea Scrolls, and more.
Unto the 1st century, the New Testament writings confirm the existence of the written Law of Moses. For which, there was no debate over what Scriptures were inspired. Jesus confirmed the Old Testament collection by mentioning its three divisions excluding the addition of the Apocrypha, which was added 2000 years later. (Apocrypha means rejected, “hidden away”.) Jesus said, “These are my words that I spoke to you while I was still with you, that everything written about Me in the Law of Moses and the Prophets and the Psalms must be fulfilled” (Luke 24:44). Jesus was clearly using all of the Scriptures for He also said, “And beginning with Moses and all the Prophets, He [Jesus] interpreted to them in all the Scriptures the things concerning Himself” (Luke 24:27). Jesus had no doubt that God oversaw and protected the Scriptures. Lastly, as a scholarly man explained regarding the collection of the books of the Bible, “If you prove the Book, then you prove the Collection.” He was saying that the numerous evidences proving that the Bible came from God proves to us that God oversaw and keeps His Book from a state of distortion and corruption.
See also “How the New Testament Came Together“.