Setting up a new Mac means remembering every tool you installed over the years. Homebrew can write that list for you, in a format it can install from.
Dump what is installed into a Brewfile:
brew bundle dump --file=~/dotfiles/Brewfile
The file is readable, one line per item: tap, brew, cask and, if you use it, mas for App Store apps. A dotfiles repo is a good home for it, I think, and you can edit out the experiments you no longer want.
On the new machine, install everything in one go:
brew bundle install --file=~/dotfiles/Brewfile
brew bundle check --file=~/dotfiles/Brewfile
check tells you whether something from the file is still missing, which is handy after a partial run.
Be careful with its cousin brew bundle cleanup. It uninstalls everything that is not in the Brewfile, so an old file can remove tools you installed since. It asks before it acts, but with --force it doesn’t, so never put that version in a script you haven’t read. And a dump is a snapshot: install something next week and the file doesn’t know, so run the dump again before you rely on it. If a file with that name already exists, dump refuses until you add --force.
Further reading: Homebrew Bundle and Brewfile (Homebrew docs), brew manpage (Homebrew docs)