Cannot ping localhost after migrating to new Mac
Your /etc/hosts file is corrupt; for some reason it has unicode LINE SEPARATOR characters added to several lines (the "M-bM-^@M-(" thing in LC_ALL=C cat -vet's output), including one of those for localhost. macOS's resolver will treat that weird character as part of the hostname, and so if you somehow manage to ping localhost&lt;LINE SEPARATOR&gt;, it'll resolve to 127.0.0.1 just fine. Plain localhost? Not so much.

I don't know how those weird characters would've gotten added; did you try to edit the file with some sophisticated editor that thought it would be a good idea to use the very latest trendy formatting characters, rather than just sticking with what'll work? If so, don't use that editor for unix-style config files (or scripts, or...). I recommend BBEdit instead; even if you don't buy it, it'll let you do the basic stuff in its free demo mode.

As for how to fix it... Well, first make a backup copy in case this goes sideways and messes things up even more than they are now. Then run the command:

sudo perl -pi -e 's/[^[:ascii:]]//g' /etc/hosts


That should purge all the weird unicode characters out of the file. Then try the dscacheutil command again; you should get something like this:

$ dscacheutil -q host -a name localhost
name: localhost
ipv6_address: ::1
ipv6_address: fe80:1::1

name: localhost
ip_address: 127.0.0.1


P.s. for a explanation why someone thought LINE SEPARATOR was a good idea, see the ever-relevant XKCD and Jeff Atwood's rant about "The Great Newline Schism".