Although not well known, the Torah states that it is not unitary. It quotes earlier songs, poems and books. This is examined in “What was the Book of the Wars of the Lord?” by Prof. Ed Greensten
…The song here is not simply presented as part of the text, but the Torah explicitly notes that it is quoting from an ancient written source for the song. (The term ספר, which we ordinarily translate as “book,” denotes any document set down in writing.)  What was this book?
Abraham Ibn Ezra (1089-1167) in his commentary (ad loc.) suggested that the reference is to an ancient and now lost written source describing the various battles fought by the Israelites against their enemies. 
R. Joseph Bechor Shor (12th cent.) and Ralbag (R. Levi ben Gershom, 1288-1344) offer the same understanding. That this document is a collection of war and victory songs in which the deity is the hero is also shared by modern scholars such as Jacob Milgrom and Yitzhak Avishur in their Olam HaTanach commentary (ad loc.), and Philip Budd in his Word Bible Commentary (ad loc.). 
…Later in this same chapter comes the Heshbon Ballad, relating to an Amorite conquest of Moab.
It may have originated among the Amorites—or it may be an Israelite song, taunting the Moabite enemy. 
The Torah quotes the song, which may well have been excerpted from a longer, perhaps even epic, poem, in order to corroborate its assertion (v. 26) that Sihon, the king of the Amorites who ruled from Heshbon, had defeated Moab (vv. 27-30):
עַל-כֵּן יֹאמְרוּ הַמֹּשְׁלִים:
Thus say the poets:
וְתִכּוֹנֵן עִיר סִיחוֹן.
Come to Heshbon—let it be rebuilt!
And let the City of Sihon be reestablished!
כִּי-אֵשׁ יָצְאָה מֵחֶשְׁבּוֹן,
לֶהָבָה מִקִּרְיַת סִיחֹן:
For a fire went out from Heshbon,
A flame from the Town of Sihon;
אָכְלָה עָר מוֹאָב,
בַּעֲלֵי בָּמוֹת אַרְנֹן.
It consumed the Steppe of Moab,
The dwellers of the Arnon’s plateau.
The Torah does not claim that this song comes from the book of YHWH’s Battles, and only says that it was sung by “balladeers” (מושלים).
Nevertheless, Ramban (Nachmanides, ca. 1195-1270) argues that this quote also comes from YHWH’s Battles
…Another way we can approach the question of this document’s nature is by comparing it to another “book” called HaYashar (“The Upright”) that is cited certainly once, likely twice or thrice, and perhaps even four times in the Bible.