You argument assumes that everyone doing what is best for themselves _individually_ is best for everyone _collectively_, which is a tragedy of the commons type scenario.
It could be argued that the very idea government – which in some way is in charge of prioritizing and allocating resources on a macro scale – is founded on the antithesis of this assumption: that in the long run what's best for everyone isn't always aligned with the short term, and they're tasked with the balancing act. Different governments tend toward different extremes, of course, but every government is on the spectrum.
If individuals doing what was best for themselves at the present moment was intrinsically tied to longterm collective stability and wellbeing, then we wouldn't need government at all!
This is all an abstract way of saying that: yes, all of those customers and employees at a Walmart in small town may be doing what's best for themselves individually by working and shopping there at the time, but once Walmart puts all those mom-and-pop shops out of business, the only place for people to work now is Walmart, the only place for people to shop now is Walmart, those who set up shops in the town (who are statistically more likely to have kids and homes in the area) now have nothing tying them to the town (and indeed, may be incentivized to move out to somewhere else to set up shop!), home vacancies go up, community events die out, and suddenly your town is a glorified Walmart parking lot off the side of a highway, and not much else. So yes, you yourself may have gotten your eggs for 20% cheaper for a time, but was it worth the longterm detriments to your home?
Hyperbolic, yes, but I've personally seen this happen to a small Texas town I drive through year after year (though, as with any rural town, there's a lot of other factors at play): eventually the protests stopped and Walmart set up shop next to the local grocery store. The grocery store went out of business, even though everyone knew the owners. The grocery store lot sat and still sits vacant. Eventually the grocers moved away with their family. The sports team shuttered in the next 3 years. Then the local school merged with the new, consolidated county school. Then the Walmart eventually closed to lack of customers. The "downtown" is a shell of what it once was, with most businesses closed and some historic buildings once worth being proud of just 10 years ago now literally crumbling beyond repair.
https://www.investopedia.com/terms/w/walmart-effect.asp