I did a quick search, and believe it or not, there are “authenticators” at every game. If a ball is used, but doesn’t leave the park, it gets a hologram sticker with a serial number, and game/inning/reason it came out of play is recorded right there. They’ll sell those on line or in the gift shop.
As for home run balls?
“While anything that goes into the stands is generally considered outside their jurisdiction, if there is a batter’s milestone occurring, the authenticators will often work with the umpires to mark up baseballs to ensure that even if the milestone ball is hit into the stands, it can be tracked and later authenticated.”
Interesting.