Deuteronomy 17:18
וְהָיָה כְשִׁבְתּוֹ עַל כִּסֵּא מַמְלַכְתּוֹ וְכָתַב לוֹ אֶת מִשְׁנֵה הַתּוֹרָה הַזֹּאת עַל סֵפֶר מִלִּפְנֵי הַכֹּהֲנִים הַלְוִיִּם
It shall be, when he sits upon the throne of his kingdom, that he shall write himself a copy of this law in a book, before the priests the Levites.
This verse recounts the obligation of a Jewish king to write a Torah scroll. The Talmud (Sanhedrin 21b) explains that the king actually wrote two copies of the Torah – one was placed in his treasury and the other remained with him at all times.