I'm referring to the front lines of a Legion, in combat. How well did they actually hold together under say, a barbarian charge. In the movie Gladiator for example, they don't at all. They break apart into individual melee immediately. However in everything I've read, the Legion's greatest strength was the cohesiveness of their battle lines.
I am most familiar with the Roman army during the Republic, which is a few centuries before the 'Gladiator' example you mention. So when reading this answer, keep in mind that though I quickly cover 3 centuries of legionary tactics (up to about 100 B.C.), I don't cover the imperial army at all.
The very early Roman legion (like 4th century B.C.) was essentially a phalanx: a wall of shields and heavy spears, which effectiveness depends on its cohesion. This system didn't work too well for the Romans though, as it is very inflexible. Over time, they made several changes:
In this system the cohesiveness of the battle line is still important, but it is not as paramount as in a phalanx. In a traditional Greek phalanx the shield of a soldier also protects the soldier to his left. For the Roman legion, this no longer applied. The oval shield only protected the soldier carrying it. It wasn't even possible to protect the soldier to the left with the shield, as the distance between soldiers was increased with the adoption of the sword. Even if you're mostly using your sword to stab and hack, you still need more room to wield it than when you're just pointing a spear forward.
This is where the three-tiered battle lines come in. The first line, the hastati, were the green soldiers who didn't have much experience. They'd enter combat, getting relieved (ideally) or reinforced by the second line if they couldn't break the enemy. The second line were called the principes and were more experienced than the hastati. Both the hastati and principes fought with swords. The third line, the triarii, consisted of the most experienced and heavily armed troops. In this period, they still formed a phalanx behind which the hastati and principes could fall back if things went awry.
Now to answer your question, though the Roman lines were very organized, in close combat they were not massive phalanx-like blocks. If battles got to this stage (many enemies would've broken from the thrown spears and the sight of the charging legion), each man needed space to wield his sword and combat would essentially be "an enormous series of duels between individual soldiers". (Daly, p. 186). Adding to the decohesion of the lines would be the corpses of the fallen, making it more difficult to move about without stumbling.
That said, you'd be unlikely to see the giant melee you see in the movies with soldiers from both sides well into each other's lines. Daly mentions:
Fuller estimated a period of fifteen minutes' fighting before men became exhausted, and Kromayer and Goldsworthy estimate even less. After a certain period of fighting it would have been necessary for the lines to draw apart, perhaps by only a few metres, in order to allow both sides to rest. Meanwhile, wounded troops might be brought to safety and line replacement could occur.
(Daly, p. 189; I have omitted Daly's references to the authors he mentions for readability.)
As the Roman Republic expanded it encountered fewer traditional enemies and got involved in more almost guerilla-style wars (especially in Spain). This led to more changes in tactics, with a greater emphasis on flexibility and less on the traditional battle lines. That's a whole different story which unfortunately I'm not very well-versed in. Perhaps someone else will provide an answer for the Marian and imperial legions.
Sources: