How does the Torah justify discriminatory charity? Why must "the poor of thine own town have prior rights"? Does this not instill a lack of desire to give to "the other"? If my friend and a stranger are both in desperate need of money or food, why should I help my friend first?
I have a guess with no source (yet):
The "own town" rule is a mechanism for making sure that no one falls through the cracks. If people donated based on some other criterion, let's say urgency of need, then, in the extreme, all donations in the world would go to the same starving town somewhere, and then would turn to the town that just got hit by a hurricane, etc. Meanwhile, poor people who aren't members of the hot spot of the day would get nothing. Making people responsible for their own local poor ensures that someone is responsible for them and takes care of them.
According to Rabbi Norman Lamm:
What the Talmud is telling us is that a totally altruistic ethic, which does not recognize intimate human bonds and affiliations, is unnatural, unrealistic, and impractical – and hence, ultimately morally valueless. An ethic that does consider and that affirms such human associations as nation, people, family, neighborhoods, is realistic and hence morally invaluable.
That would seem to be an acceptable and self-evident principle. Yet the need the Talmud saw for legislating this rule indicates, according to the historian’s device we mentioned earlier, that this principle was often violated. There were, and are, apparently, many people who would rather assist the stranger than the acquaintance, would rather benefit the non-relative than the relative.
Indeed, I would diagnose this phenomenon as an American Jewish disease! Western Jews, since the Emancipation, have grown up on the myth of “Universal Man,” a universalism which negates ethnic identity and national-religious uniqueness. It is the kind of myth which, for many years, fed anti-Zionist classical Reform and the American Council for Judaism, which, thank Heaven, we hear less and less from as time goes on.
I would myself add that arguably the biblical paradigm of inverting this principle is Lot who would have had his own daughter be persecuted rather than a stranger.
Although from the gemara it seems like a regular drasha from a pasuk, meaning don't blame this on the Talmud, there seems to be an interesting explenation that I'd like to point out.
The way the עץ יוסף on the Medrash Tanchuma explains it, this is actually a device for self preservation.
In parshas Mishpatim on the words אם כסף תלוה, the Tanchuma (#15) spends much time explaining how people should give and lend to each other. The medrash then points out how these acts must be done without embarrassing the poor person, שהוא עמי, darshaning the word ׳my nation׳ as if it has two חיריק and is pronounced ׳with me׳. The Tanchuma says this is the source of the drasha ענייך ועניי עירך, ענייך קודם. עניי עירך ועניי עיר אחרת, עניי עירך קודמין לעניי עיר אחרת.
The medrash goes on to say that Hashem is in charge and if the rich man won't be kind to the poor man, Hashem will reverse their roles. The Medrash brings a pasuk calling them brothers, proving their equality, ending with the words לפיכך, את העני עמך.
Upon these words the Eitz Yosef says the medrash is trying to convey the point that the rich man should be kind to the poor man so that the poor man should in turn be kind to him, for being poor is a turning wheel in the world and today or tomorrow he or his children will need help.
I think it's obvious from the flow of the medrash and the intent that this insurance policy of kindness will work better the closer the investments stay to home. Which is why we find varying levels of whom to give, family members, fellow citizens of your city, etc.