I ran this line in Terminal:
sudo chown -R $USER /usr/local
Now I want to reverse it to the default permissions. How do I do that?
(I think the default owner is system)
By default /usr/local is owned by root and the directories under that don't exist so there could be odd users under that, if so the restore as per patrix's answer otherwise
The most usual setup in Unix/Linux is to have them all owned by root. So
sudo chown -R root /usr/local
There is no such user as system by default,
There is no standard way to do this. Easiest approach would to to restore the /usr/local
hierarchy from your most recent backup (and manually reapply all changes/installs made later).