The Babylonians sacked Jerusalem and conquered the biblical kingdom of Judah in 587 BCE. Just before then, c. 600 BCE, Judah maintained a small military outpost at Tel Arad, about 20 miles south of Jerusalem. Written inscriptions have been found there on ostraca (pottery fragments), a common writing medium in the ancient world. The fort at Tel Arad was a small place, with a garrison of 20-30 soldiers. Yet a handwriting analysis of 18 incriptions shows that there were least 6 and perhaps as many as 12 authors of these texts. This indicates that literacy was not uncommon in Judah at the time, at least among the army. It was not the exclusive domain a few scribes serving the king.
Given a substantial degree of literacy, it is plausible that some of the books of the Hebrew Bible, e.g. Deuteronomy, Joshua, Judges, Samuel, and Kings, were in fact written down before the fall of Jerusalem and the Babylonian exile.