Why didn't the Buddha write a book?
Well, he needed writing material and he needed a written script.
Now, a written script has to be one that many people can read and comprehend, otherwise it's useless.
How do languages and written scripts get standardized, taught widely and made official? Through the ruler or government of a country of course.
The following article proves that during the Buddha's lifetime (c. 563 BCE to 483 BCE), there was no official or ubiquitous written script in the region where the Buddha lived, till Emperor Asoka over two centuries later, who had inscriptions carved on stone pillars in the Brahmi script.
Earlier versions of the Brahmi script may have existed in Tamil Nadu (south India) and Sri Lanka at the time of the Buddha, but certainly not in the region where the Buddha lived.
From "The Story of India’s Many Scripts" by Akhilesh Pillalamarri in The Diplomat:
India has a long history of writing. While India has been a literate
culture for millennia, it has also greatly valued oral knowledge. The
ancient Hindu scriptures, the Vedas, the oldest of which dated to
around 1500 BCE were memorized verbatim for at least a thousand years,
if not more, before being committed to writing. The oldest writing
found in the subcontinent is the as yet undeciphered script of the
Indus Valley Civilization (IVC), which seems to have been somewhat
logo-syllabic in nature. The script fell out of use by 1500 BCE.
The linguistic landscape of the subcontinent changed dramatically
during the 2nd millennium BCE, so that is is impossible to determine
if there is a connection between the IVC script and the next clearly
attested script in India, the Brahmi script found in the inscriptions
of the Mauryan Emperor Ashoka (ruled 268-232 BCE), especially since
they probably represented vastly different, unrelated languages.
The sudden appearance of the Brahmi writing system is one of the great
mysteries of writing in India, as there is no evidence of inscriptions
beforehand. Another script, the (extinct, childless) Kharosthi of
northwest Pakistan and Afghanistan seems to be clearly derived from
the imperial Aramaic script used by the Persians who ruled over parts
of the Indus Valley for two centuries until the arrival of Alexander
the Great. It is unclear if the fully developed Brahmi script was
invented by the Mauryan Empire as a result of exposure to Aramaic, but
this seems unlikely, particularly since there were advanced states in
the Ganges valley and a corpus of Vedic literature dating from before
the Mauryan period.
It is more likely that pre-Mauryan inscriptions may still be
discovered, and in fact, some Brahmi inscriptions have been found in
Tamil Nadu and Sri Lanka dating to the 6th century BCE. Is it possible
then, that writing spread from the south to the north, countervening
the traditional notion that the Indic scripts originate in the Ganges
valley? This may quite possibly be the case, especially since the
coasts of southern India were more exposed to foreign trade from the
Middle East than northern India, and scripts from traders could have
been brought to India this way (the same way the Phoenicians brought
their script to Greece). This long gestation period and overland route
from southern to northern India may explain why the Brahmi script,
even if it is vaguely derived from Middle Eastern alphabets, is so
different and nativized, especially relative to the more obviously
Middle Eastern-inspired Kharosthi.
Once the Brahmi script was spread throughout India by the
subcontinent-wide Mauryan Empire, it was used by the subcontinent’s
elites. However, unlike imperial China with its unified central
government and bureaucratic exam system, and Christian and Muslim
societies that were united by a written scripture, oral culture and
regional differences in India led to the Brahmi script differentiating
and evolving into different scripts in various regions of India, a
phenomenon that was already occurring by the end of the Mauryan period
in the 2nd century BCE. This phenomenon—each literary language having
a particular and unique script — is not actually that unique to India,
as the various languages of the ancient Near East and Mediterranean
also evolved their own scripts from a common source.
The article above continues with a commentary on writing material.
The following paper excerpt shows that Emperor Asoka's stone pillar inscriptions referred to suttas by name, from the oral tradition.
From Wynne, A. (2004), "The Oral Transmission of Early Buddhist Literature", Journal of the International Association of Buddhist Studies, Volume 27, Number 1, p. 97:
In his Calcutta-Bairat edict, Asoka names some texts, the study of
which he considers advantageous. The general consensus seems to be
that what Asoka calls Munigatha correspond to the Munisutta (Sn
207-21), Moneyasute is probably the second half of the Nalakasutta
(Sn 699-723), and Upatisapasine may correspond to the Sariputtasutta
(Sn 955-975). The identification of most of the other titles is less
certain, but Schmithausen, following Oldenberg before him, identifies
what Asoka calls the Laghulovada with part of a prose text in the
Majjhima Nikaya, the Ambalatthika-Rahulovada Sutta (M no.61). It is
hardly likely that Asoka knew these texts in exactly the same form as
they are found in the extant Suttapitaka, but this does not matter.
What matters is that Asoka was able to name texts, and this surely
means that their content was more or less fixed.
As a side topic, while a common written script was not available, spoken dialects were ubiquitous and subject to the phenomena of dialect continuums. This is the reason why there was no one single language or dialect called Pali, but it was formalized later, based on the dialects of the Buddha's time and region, plus later partial Sanskritization. So, the other thing to note is that there was no formal Pali language at the time. Please also see this answer.
Some kind of formal Sanskrit (pre-Panini) may have been present at the time, but not available to the common folk, so the Buddha had forbidden its use for transmission of his teachings - please see this question.