The blue fairy realized that Gepetto did not follow her instructions since Mary Margeret (Snow White) was in Storybrooke. He instead sent Pinnochio through the portal, against her wishes.
She must have written the book after Henry showed up in Storybrooke. But that’s too convenient of a coincidence – how could she know he was Emma’s child?