The development of writing was gradual. It likely started up many times, had some success, only to be lost to the sands of time. We know about a few going back about 5,000 years, but earlier attempts almost certainly existed, though we have to focus on what we find.
There are essentially three main types of written language: logographic, syllabic, and alphabetic. Logographic systems use pictures to represent words. For example, Chinese characters, ancient Sumerian cuneiform, and Egyptian hieroglyphics are all logographic systems. Syllabic systems use symbols to represent syllables, reproducing the audible bits of a spoken language. An example of this is the Japanese kana scripts, where each character represents a syllable. Finally, alphabetic systems use symbols to represent individual sounds (phonemes), not whole syllables. Examples include the Latin alphabet.
So, why did we start writing? There are various theories, and one clear reason is the desire to preserve spoken language. Beyond this general reason, specific theories include record-keeping and labeling. In ancient Mesopotamia, for instance, clay tokens were used to keep track of goods and transactions. Over time, these tokens evolved into cuneiform. This suggests that cuneiform writing, and perhaps others, developed to manage economic transactions and inventories. Another idea says that writing began with the need to label and identify objects and places. Hieroglyphics, for example, may have started this way. Perhaps it started by marking things–perhaps an “X” for areas to watch out for or symbols for places like bathrooms.
For a deeper dive into the evolution of vocabulary in human ancestry, take the deep dive: The Evolution of Vocabulary in Ancient Humans.