Magic is a weird and mysterious power. Only the brightest and best unicorns could perceive all the outcomes and very rarely failed. Twilight Sparkle is a young up-and-coming unicorn trained by Celestia herself. Even having that training though isn't always enough to make a spell work flawlessly. Sometimes the spell will do things that the caster did not intend.