And why other enemies Greeks fought with weren't able to do the same?
The Phalanx was the 'normal' way of fighting for most civilizations in the mediterranean. The Romans also fought like that untill they had the wars against the Samnites. The Samnites had to be fought in the Italian hills (the Appenines) in which Phalanx Formations could be broken up very easily. Because of this the Romans changed their tactics to the Maniple formatioon, these where groups of 120 men who could be moved around better than the cumbersome Phalanx.
The Romans kept this formation after they finally defeated the Samnites and used the same formations untill the Marian Reforms around 100 BC. This is why they could defeat the Greek and mostly Macedonian armies in Greece and Italy, they could manoeuvre around the Enemy and outflank the Phalanx formations, at which point a Phalanx was completly useless.