Why did Holden write Mr. Spencer a note at the end of his examination paper?
Holden writes the note to Mr. Spencer "so that he wouldn't feel too bad about flunking me."
If Holden doesn't think that Mr. Spencer is a phony, he does think of him as somewhat pathetic: frail, sick, smelling of Vicks and picking his nose. He also feels that Mr. Spencer plays a "dirty trick" on him by reacing Holden's examination paper - complete with note - to him. He resents Mr. Spencer bringing up his previous two schools. But as he's about to leave, realizes that he feels sorry for him. Holden frequently sees, along with the phoniness around him, people for whom he feels sorry, and wants particularly not to hurt. He feels guilt about lying (though he does it all the time), and his protective nature wants to shield the "nice old guy" from harm.
Because he knew how awful his writing was and he wanted to apologize to Mr. Spencer before he read it. Holden has already experienced a world of "phonies" and he wants the teacher to know he is not one of them. (Chapter Two is where you will find this scene.)