The simple answer to this question is that we do not know. William Shakespeare did not write any sort of autobiography in which he explained his reasons for writing plays. Although we do know the dates of the first productions of his plays, that is not the same as dates of composition; he could have written the plays months or years before they were actually produced.
What we do know is that he started his theatrical career as an actor in The Chamberlain's Men. He could have initially written plays to create better roles for himself or because he saw writing them as a way to earn more money. Possibly, though, he just enjoyed writing plays. His career combined writing plays and managing a company of actors, and so his later works may have been written to provide unique material for his company.
For dates, we know that the three parts of Henry VI were first performed over the years 1590-1592, and Richard III and Comedy of Errors in the 1592-1593 theatrical season. The Two Gentlemen of Verona and The Taming of the Shrew may have been written slightly earlier (1589-1590) but the evidence is somewhat speculative.
It is believed that Shakespeare wrote his first plays, The Two Gentlemen of Verona and The Taming of the Shrew, in 1590. We do not know a lot about Shakespeare's life, but we do know that we began as an actor in The Chamberlain's Men. His success and happiness as an actor probably caused him to move on to writing the plays as well. It's just our luck that he was good at it! Shakespeare understood the human spirit, despite (and possibly because of) being mostly self-educated, and he captivated his insights through his works.