You might assume this idea came from the show's writers and not any of the cast members. Believe it or not, many of the cast members of The Office are also writers, including Mindy Kaling (Kelly), Paul Lieberstein (Toby), and B.J. Novak (Ryan). This scene was the brilliant idea of Kaling, who was inspired when she saw Dwight dress up as Pam (Jenna Fischer) to trick Jim (John Krasinski) and attack him with snowballs.
"When I was writing the episode, I just thought how funny Rainn would look in the Meredith wig," Kaling revealed in a 2010 interview with Office Tally. "The stage direction was 'he whips around like a dramatic hamster.' I think Rainn and Matt Sohn, our DP really captured that detail. Stanley is probably my favorite, the way Rainn held up that crossword puzzle with all that seriousness. Also, Matt made the perfect suggestion that we stuff the back of the blazer with a pillow, to give Rainn some more Stanley-like heft."
Once the idea was born, hair and makeup immediately went to work. Hairstylists Kim M. Ferry and Sari Perry were significant contributors to this scene, and even helped with filming before the episode's deadline.