TL;DR - It's because financially, it pays off for longer, more popular anime series. It allows them to retain broadcasting slot, as well as sponsors and advertisers, by sacrificing a bit of quality.
First, it needs to be pointed out that many anime don't have filler. Filler episodes are only common in long-running popular anime such as One Piece, Naruto, or Bleach. This is because of the particular profit model they have. These long-running shows make a profit through sponsorships and advertisements. In contrast, shorter works, especially late night anime, only make a profit through sales of blu-rays and other merchandise. Hence, for long-running shows, the quality of individual episodes is somewhat less of a concern.
Given that the episodes need to be around 20 minutes long (excluding OP and ED sequences) and air once a week to fit into TV programming schedules, the anime almost always needs to go faster than the manga. Hence, there are essentially 3 options for what to do. Most commonly, they will just add a few irrelevant "filler" episodes occasionally. This does tend to make viewers unhappy if they're too common, but production studios have determined that viewers are less likely to stop watching if fillers air than if the anime just takes a break.
Another option is to take a break whenever the anime gets close to the manga. This is the strategy Gintama takes as well as most late-night anime that are popular enough to be adapted fully (e.g. To Love-Ru). It results in higher quality, but it's harder to keep sponsorships and TV slots when the show airs infrequently, and viewers may drop it during the break. One Piece has done this at times and aired fillers at other times. The third option is to abandon the manga entirely and write an original story. Some works that did this are Fullmetal Alchemist (the original), Hayate no Gotoku (1st season), Hunter x Hunter (original) and Soul Eater. This used to be much more popular, especially in the 1990s, but it makes it more difficult to continue the anime and fans usually aren't happy with the changes, so these days it's become very uncommon. Notice that 3 of these 4 ended up needing to be rebooted or have large retcons to have anime continuations, and the fourth hasn't been despite a large following simply because of the difficulties involved.
So, to put it simply, these long-running shows have filler because that's their best option to keep their TV slots, sponsors, and viewers. It does cost a bit of quality, but that's acceptable for highly popular shows like this where quality is somewhat less of a concern.
As for why they can't just speed up the manga production to accommodate the anime, that wouldn't really be feasible. Manga production is mostly done by a single mangaka with an editor and sometimes one or more assistants, while a single anime episode may have dozens of animators working on it. In the case of popular works, essentially everything that can possibly be is left to the assistants. Apart from splitting up story and artwork, there isn't much that could be done to speed up the process, and few mangaka want to do that (though it has been done in some cases). Furthermore, managaka are already ridiculously overworked; the rate at which manga is produced right now is basically as fast as it can possibly be produced. To get rid of fillers, production would need to be sped up significantly (roughly 50-100% faster for most works), and it's hard to imagine any way to do that.
In addition, it wouldn't really help the manga to be produced faster. Most of these manga are released in weekly magazines which contain a chapter of several works. If production was sped up drastically, this would mean fewer works could be included in a single issue. It's likely that this wouldn't really increase revenue, since these works typically target younger children and adolescents without a large amount of disposable income, but it would drastically increase the production costs per series. Given that the manga and anime are produced by two completely different companies, that relatively few manga ever get adapted to anime, and that the manga is often more profitable than the anime, there's really no reason (and no realistic way) to speed up the manga just for the sake of eliminating anime fillers.