Twilight Sparkle is in a foul mood and wants nothing more to be alone after a magic mishap with Rainbow Dash.
Pinkie Pie wants to help cheer up Twilight, and decides to write a story for her, with the help of Spike.
Little did Twilight know this was a bad idea from the start.
As reviewed by Seattle's Angels!
ETA: I am relieved to state this story predates issues #15-16 of the IDW comic series, which similarly involves book stories coming to life, albeit in a different setup and resolution. Also, as this was already set canonically before the finale of Season 3, I don't consider there any retcon issues with the reveals of S4E4 of the show, as well as working within the premise that S4E6.