Deuteronomy 31:25

That Moses commanded the Levites, which bare the ark of the covenant of the LORD, saying,

The command came at Moses' last opportunity to address Israel before his death in Moab, as he finished writing and gave repeated and enlarged laws with explanations of the precepts, reasons for them, and methods for enforcing them, repeating commands that had been transgressed to make clear that disobedience would bring God's punishment. Those he commanded were the Levites who bore and carried the ark of the covenant and served in connection with it, men in sacred office appointed for the task and entrusted as appointed officers with the written law. The book he put in their charge was written by Moses himself and contained all the laws, judgments, and statutes God had given him.

It included regulations respecting sacrificial offerings, all the instructions given to Israel by the way, all the miracles performed for them, and all the murmurings of the children of Israel, including the record of Moses being overcome in consequence of their murmurings. The commands given to Israel were thus recorded in books to be carefully preserved as God's commands. Moses charged the Levites to put the book in the side of and beside the ark for safekeeping in that most sacred and protected place, where God's care continually rested upon the sacred chest.

The book was to be preserved there as a sacred record for future reference, so that Israel's judges could refer to it when any case made it necessary. It was kept there because an erring people often understand or distort God's requirements to suit their own case and desires, and could not then reshape them to suit themselves.