The injuries endured by Frodo Baggins (Elijah Wood) over the course of Lord of the Rings are why he chose to leave Middle-earth at the end of the trilogy. At the conclusion of the third and final film in the trilogy, Lord of the Rings: Return of the King, Frodo makes the fateful decision to leave his ancestral home for the legendary realm known as the Undying Lands.
In Return of the King, after the ring has been destroyed and Sauron defeated, Frodo returns to the Shire and gets a job as its Deputy Mayor. Later, Frodo is seen on an Elven ship alongside Gandalf (Ian McKellen), Bilbo Baggins (Ian Holm) and others. The ship leaves the Grey Havens and sets off for the Undying Lands, a special place outside of Middle-earth which is only welcome to immortals and Ring-bearers. This is how Frodo's journey finally ends, but why didn't he stay in the Shire with the other hobbits?
Frodo left Middle-earth because of what happened to him during Lord of the Rings. He experienced two injuries which never completely faded, meaning he couldn't stay and be happy in Middle-earth. In Fellowship of the Ring, the hobbits were ambushed by the Ringwraiths, creatures whose primary goal is to serve Sauron and find the Ring. Frodo tried to use the Ring to hide from them, but was stabbed in the shoulder by the Witch-King.
A year later, Frodo sustained another injury in Return of the King. When Frodo and Samwise Gamgee (Sean Astin) were in the tunnels on their way to Mordor, they had a terrifying confrontation with a giant spider called Shelob. They tried to escape from the spider, but Shelob attacked Frodo and used her stinger to poison Frodo. Frodo recovered, and didn't let his injury stop him from fulfilling his goal and destroying the Ring at the end of the movie.
Frodo experienced much emotional and physical trauma during Lord of the Rings, but perhaps what bothered Frodo the most was the annual return of these two injuries. On the anniversary of his stabbing at Weathertop, he would feel the pain of his shoulder wound all over again. He had a similar experience on the anniversary of the incident with Shelob. What this means is that Frodo could never move on from what happened, and it would always come back to haunt him every year. The only way for Frodo to find peace was for him to leave Middle-earth and head to the Undying Lands, in the hopes that this mystical realm could finally heal his injuries forever.