I'd say that at least 99.99% of all sex scenes in movies are absolutely unnecessary. Way more often than not, they are used for one purpose more than any other: boosting ratings.
Why boost ratings at all, you might ask? Simple, really: in general, many studios & directors are under the impression that if a film doesn't include sex, blood, and/or crude language, then it's a "kiddie flick", and thus won't appeal to a bigger audience...which is just trash. The average family film makes 10 times the amount of its R-rated counterpart.
If an ordinarily R-rated film were stripped of its "overkill content" and actually stuck to the actual story, it's my opinion that over half of them would be given a lower rating by the MPAA. The first "Matrix" film, for example, contains a scene in a fetish club (where Neo meets Trinity), and multiple uses of God's name while swearing. If that scene had taken place inside a less-provocative venue, and the lanuage been toned down a bit, the film's rating might have been different, and the story's integrity would've still been intact. The boundaries are constantly pushed to make money, often at the expense of the film itself. That's just one example.