How did literature originate?
The different genres we now consider literary originated at different times and in different contexts. Epic and wisdom poetry was rooted in oral tradition before speech was invented and served to preserve important cultural memories about gods, heroes, ancestors and cultural traditions in performance. Lyric poetry was primarily entertainment, usually accompanied by music. Tragic and comic poetry originated in archaic Greece and were originally performed as parts of religious festivals and the prose novel originated in the Hellenistic period.
The general notion of "literature" per se was Hellenistic, when we find terms like "paideia", "grammata", and "littera" applied to a canon of works studied by students learning to read; these were works chosen as culturally significant and knowing them was essential to being considered an educated person.