Diving is what we generally call a player's attempts to deceive the referee into calling a foul when none has been committed, either by falling down or gesticulating in more dramatic manner. Here's the first problem: players don't fall down just to deceive the referee into calling a foul; in fact, more often they fall down to indicate to the referee that a foul has occurred, merely to make it easier for him to call it.
Now why would a player ever need to do that? The first part of the answer is that referees are simply less likely to call a foul when it's not as obvious. Unfortunate but fair. The second part of the answer is more pernicious. Referees are also less likely to whistle for a foul when a player still has any sort of control over the ball, because of the advantage rule. That is, players often suffer minor fouls, but because they more or less still have the ball, the referee lets play continue.
Therefore, players are often (unconsciously) making a choice when they flop: continue with what measly advantage I may or may not have continuing with the ball, or cut my losses and take a free kick now.
If I could draw a really convoluted analogy to game theory, the situation is like a Nash equilibrium from which neither player nor referee has much of an incentive to deviate, because of the convoluted rules of soccer and the way referees traditionally call games. That is, referees are faced with a false choice that they have to buy into: call a foul, and ignore the attacking player's role in making it obvious, or call a dive and ignore the fact that a foul may have occurred.
The worst part is, players who don't play along with this little game are punished along wiht their teams. Here's where we go back to the Barcelona game. Before Inter's third goal in the first leg, Leonel Messi was carrying the ball up the field and was clearly fouled, as he was time after time in the match. But instead of flopping, he tried to carry on. Instead of then receiving a free kick for his trouble, after a he subsequently lost control of the ball, the referee was forced to decide that, since he had already played advantage, play had to continue. From the counter-attack, Inter scored their third goal.
So what's the solution? First: disambiguate diving from fouling. Both can take place simultaneously. Secondly, referees have to start calling fouls when players don't dive, or they remain complicit in the epidemic of diving. And third, change the advantage rule.