We cannot pinpoint with accuracy why Khaled Hosseini wrote the novel. He even says that the story was imaginary. But we can take a few educated guesses.
First, Khaled Hosseini grew up in Kabul, Afghanistan. He was born on March 4, 1965. His father was a diplomat and his mother was a teacher who taught Farsi. He also loved kite fighting and Western films, like Amir. So, we can say that his childhood, at least in part, inspired his story.
Second, when we look at some of the themes of the book, we can also say that only someone like Hosseini could write this book. As one who left his country to live in America and one who saw his family adjust to a new life in a foreign land, he could draw from his own experiences in describing his main characters Baba and Amir. In other words, personal experiences may have inspired his book.
Finally, when it comes to his more universal themes, such as redemption, we can say that it is a great story to tell (and to read). So, if we combine all these elements, what we have is a beautiful novel.
I suspect that in the end, Hosseini wrote the novel because it was a story worth telling.