Except that they don't. Paying for someone who can already afford the food anyway (they wouldn't be in the line if they couldn't afford that $5 coffee) isn't contributing anything meaningful. If 100 people do that, it still isn't meaningful or helpful. It actually reduces the amount of money spent on genuinely needed charity, if people feel they are already doing their part by occasionally picking up the coffee tab of fellow members of the middle class, instead of donating money to worthy organizations that help those who are really in need.
You can donate your money to whoever you feel is most deserving. You are presenting a false choice. It’s not pay for the other person or give to XYZ charity - it could just be they are going to pay for the other person or they’re going to keep it in their pocket. Just because you don’t find something meaningful doesn’t mean the other person isn’t. If you want to donate your money to the homeless then go right ahead — you can donate 100% of your wealth if you so desire.