A question I’ve seen come up among fans of The Hobbit book is “where is all this extra stuff coming from?” It’s a fair question if you’ve only read The Hobbit, as there are many events in the film that are totally absent from that text.
The fact of the matter is, despite the film’s name, Peter Jackson isn’t really adapting The Hobbit so much as he’s adapting The Quest of Erebor, which is Tolkien’s name for the larger, more inclusive story that involves more than just Bilbo’s adventure at the time. While some of the events and timelines have been condensed or shuffled around, there’s actually very little in The Hobbit film that’s not taken from Tolkien’s writings, in fact less than The Lord of the Rings films.
What many don’t know is The Hobbit was actually written before Tolkien had decided that it would directly be a part of his larger Middle-Earth universe, and only in later editions did he actually change its text to make it fit into that continuity (most notably, Tolkien re-wrote the Riddles chapter, where originally Gollum gave Bilbo the Ring as a prize). Even so, many details in the story contradict the larger narrative, and this was chalked up to Bilbo embellishing or omitting events, or simply not being aware of some certain aspects of what was occurring around him. Unlike The Lord of the Rings, The Hobbit is written from the limited perspective of only a single character, and many character motivations and contexts (like why exactly Gandalf would use a Hobbit to begin with and the jarring introduction of Bard the Bowman) are absent. This is fine for The Hobbit in itself, which is largely just a fairy tale, but as a prequel to The Lord of the Rings, Tolkien felt it fell short.
With this in mind, after drafting The Fellowship of the Ring, Tolkien began writing The Quest of Erebor, which told Bilbo’s story in a style closer to The Lord of the Rings, including Gandalf’s adventures concerning The Necromancer, Saruman’s growing obsession with the Ring of Power and so on. For space reasons, Tolkien was only able to include a condensed version of this story in the appendices of The Return of the King, but the complete story was published in Unfinished Tales in 1980.
Peter Jackson does not have the rights to directly adapt Unfinished Tales, but there is sufficient content in The Return of the King alone to justify making The Hobbit into three films. A strict adaptation of The Hobbit book or a larger one of The Quest of Erebor are equally legitimate, but the latter is a much more effective way to create a prequel to The Lord of the Rings, which is Peter Jackson’s intent. For those more interested in a film adaptation of The Hobbit alone, I’d recommend the Rankin-Baas version from 1977, though even then it had to make concessions for many of the fairy tale logic problems found in the book.
I hope that explains the additional scenes for people who were curious!