Three friends brought 3 pens together each 10 dollars. Next day they got 5 dollars cash back so they shared each 1 dollar and donated 2 dollars. Now the pen cost for each guy will be 9 dollars (\$10 -\$1).
But if you add all 9+9+9 = 27 dollars and donated amount is 2 dollars so total 29 dollars.
Where is the other \$1?
The last conclusion is simply wrong. You are right, they paid $27$ dollars altogether. The pens however cost $25$ dollars ($30$ dollars initially, then $5$ discount), so that's the two dollar donation difference.
There is no sense in adding the $2$ dollars, since the nine dollars each friend spent includes the donation.
EDIT: As T. Bongers noted, this is a known fallacy, so you might want to check Wikipedia or google for "missing dollar" for more detailed explanations.