What isn't explained properly in the films is that when the One Ring is destroyed, the power of the Three Rings (held by Galadriel, Gandalf, and Elrond) is broken, effectively ending magic in Middle Earth at that point. That's why the Elves have no choice but to leave. What's more all Ring Bearers have to leave too (which includes Sam, once he's led a full and happy life, as detailed in the appendixes of the novel). In Frodo's case, he had to leave earlier because he was basically dying due to the various other wounds he sustained along the way - from the Morgul blade, Shelob's stinger, and so forth, plus the fact that the Ring broke his mind at the very end, before it is destroyed. When he leaves Gondor, Arwen gives Frodo a white starlight gem to help him with the pain, but she knows it is only a temporary solution. And sometimes, Sam finds Frodo collapsed at Bag End, or in a feverish fit, crying out for the Ring. So yes, he had to go sooner.