To understand why Orwell wrote Animal Farm as an allegory, it is useful to look at his explanation in the Preface to the Ukrainian Edition in which he outlines two key reasons.
Firstly, Orwell states that he felt compelled to tell the world about the horrors being committed by Stalin in the USSR:
"It was of the utmost importance to me that people in western Europe should see the Soviet regime for what it really was."
For Orwell, Stalin's politics were so far removed from true Socialism that he wanted to tell the world about it.
Secondly, he wanted to portray this story in a way which made it easy for people to understand:
"I thought of exposing the Soviet myth in a story that could be easily understood by almost anyone and which could be easily translated into other languages."
The inspiration for a farmyard came a short time later when he saw a little boy, aged around ten years old, driving a "huge cart-horse" and whipping it "whenever he tried to turn." It suddenly occurred to Orwell that if this animal realised its strength, it could easily overpower the boy and the rest of our society. From this, Animal Farm was born.
To read the Preface in full, please see the first reference link provided.