Answer:
First, 3 people divide $30, then each one of them pays:
$30/3 = $10.
Each one of them gets $1 in refound.
Then at the moment, each one of them paid $9, and there are 3 friends, so the total amount is 3*$9 = $27.
We also know that the cashier keeps $2, but these $2 must come from the $27 that the friends paid.
Then we will have $27 = $25 + $2.
This means that the total cost was $25, and the cashier kept $2 as a tip.
Now, in your problem, you add the $2 that the cashier kept to the $27 that the friends paid. While those $2 actually are already counted in the $27 that the friends paid.