It can be argued that some swearing is overused and unnecessary but some films contain swearing because some people swear in real-life, and it can make a film more dramatic or shocking.
It depends on what is considered swearing, which has changed over the years as sensibilities change, and also on culture, but swearing dates back to silent films.
From The Douglas Fairbanks Museum:
Vintage news articles from the museum’s newspaper and magazine archives were requested by the network specifically pertaining to the 1916 Douglas Fairbanks comedy, The Habit of Happiness – reportedly the first Hollywood film to contain a curse word. And this was in the silent days before spoken dialogue!
Although there are no swear words in the printed title cards, Fairbanks reportedly swore up a blue streak in one particular scene, sparking a nationwide lip-reading movie controversy.
From IMDb's Gone With The Wind (1939) FAQ:
Was this the first movie to use profanity?
No. "Damn" was surprisingly common in intertitles of silent movies, and John Gilbert even shouts "Goddamn you!" to the enemy during battle in The Big Parade (1925), and cries, "Christ! He's dead!" in The Show (1927). Talkies that used "damn" include Glorifying the American Girl (1929), Gold Diggers of Broadway (1929), Hell's Angels (1930), The Big Trail (1930), The Dawn Patrol (1930), The Green Goddess (1930), Dirigible (1931), Blessed Event (1932), The 39 Steps (1935), The Man Without a Country (1937), and Holiday (1938). GWTW wasn't even the first Best Picture Oscar winner to use "damn": Clive Brook says it in Cavalcade (1933).
From Digital Spy Forums:
You'd have to define your 'swearing' boundaries.
I think Who's Afraid Of Virginia Woolf? (1966) was the first American film to feature a fairly liberal use of words accepted as 'swearing' (several bastards, bloodys and buggers), as opposed to just mild 'cussing' of the damn and blast variety. 'One or two' instances of those had been accepted in British films for quite a while though.
According to Wikipedia's fuck article (which goes into much more detail):
The films Ulysses and I'll Never Forget What's'isname (both 1967) are contenders for being the first film to use the word 'fuck,' although the word 'fucking' is clearly mouthed silently in the film Sink the Bismarck! (1960), and the title character says it in the cartoon Bosko's Picture Show (1933).
Since the 1970s, the use of the word "fuck" in R-rated movies has become so commonplace in mainstream American movies that it is rarely noticed by most audiences. Nonetheless, a few movies have made exceptional use of the word, to the point where such films as Fuck, Good Will Hunting, Casino, The Last Detail, Menace II Society, The Big Lebowski, The Departed, Scarface (1983), Pulp Fiction, Blue Velvet, South Park: Bigger, Longer & Uncut, and Goodfellas as well as the HBO TV series The Sopranos are known for its extensive use.
From several posters on the Straight Dope Message Board:
John Gilbert, via intertitle, shouted "goddamn it" and "b------s!" (sic) during the heat of the battle in the hugely successful The Big Parade (1925).
In the closing line of the exotic The Green Goddess (1930), George Arliss, as a Asian tyrant, dismisses a woman who escaped his clutches with the comment, "She probably would have been a damned nuisance, anyway."
Another World War I epic, Hell's Angels (1930), really let it rip: you could hear "It's me, goddamit", "What the hell", "For Chrissake", "Jesus!", and "That son-of-a-bitch!" amid the aerial dogfights.
Even after the Motion Picture Production Code began to be enforced in 1934, there were pre-Gone With the Wind uses of "damn", including Katharine Hepburn quoting Lady Macbeth's "Out, damned spot" in Holiday (1938). The earliest Code-era "goddamn it" I know of was from Don Murray in Bus Stop (1956).
Scott Wilson was the first to say "shit" in an American feature, as one of the murderers in In Cold Blood (1967).
The first major Hollywood film to use "bullshit" was Bullitt in 1968.
Coincidentally, I've been trying to find the first mainstream American movie to feature the most taboo word of all - "cunt". I know it was in Boys In The Band from 1970, but I think there may be an earlier instance.
Rip Torn in The Cincinnati Kid (1965): "Yes, for my kind of money, gut money. I wanta to see that smug old bastard gutted. Gutted!"
There are supposedly several cases from the silent era where lip-readers did complain about swearing in the dialogue. In this vein, there's a scene between Edmund Lowe and Victor McLaglen in What Price Glory (1926) that reputedly caused problems, as did some of Gloria Swanson's language in Sadie Thompson (1928). Similarly, there's the case of Douglas Fairbanks and the dirty joke in The Habit of Happiness (1916).