It's often a chance for actors to show off their range, especially as we're watching both performances play out simultaneously. Created by Andy Schneider and Jonathan Britnell of Burger Fiction, here's a great rundown of some of those terrific moments in cinema history:

Easily the most impressive one to me is Buster Keaton's from The Playhouse, as it was all done straight in the camera. Keaton played around with difficult in-camera effects all the time, as there was no real way to do this in post-production at the time. Here's an explanation of how he did it from Wikipedia:

Keaton's portrayal of nine members of a minstrel show required the use of a special matte box in front of the camera lens. It had nine exactingly-machined strips of metal which could be moved up and down independently of each other. Elgin Lessley, Keaton's cameraman, shot the far-left Keaton with the first shutter up, and the others down. He then rewound the film, opened the second segment, and re-filmed the next Keaton in sequence. This procedure was repeated seven more times. The camera was hand-wound, so Lessley's hand had to be absolutely steady to avoid any variation in speed. Keaton relied on a metronome to guide him, not a problem in a silent film. It was decades before Keaton, who masterminded this, revealed his technique to other filmmakers.

With digital technology, putting the same actor onscreen at the same time has become infinitely easier (and if we never see both faces at the same time, it's really easy). In the days of optical film processing, however, one technique required the same sort of mattes that were done for other visual effects. A matte would have been created around the actor or split right down the middle of the frame, and then the film would have to be printed again in order to combine the elements together.

These days, this sort of technique is used for all sorts of other purposes besides the one above, like using different takes from different performances in the same wide shot. This is apparently something David Fincher does a lot, when he likes a performance in one take over another, but wants to keep parts of the shot. Here's Ben Gill on this effect and just one of the ways you can do it yourself:

Which "actor acting opposite themselves" performance or movie is your favorite? 

Source: Burger Fiction