How can I change the ownership of the unwritable directories for Homebrew?
I would start with a simpler command. 

sudo chown -R 501 /usr/local/share/aclocal


Use a user number instead of name to see if that’s he error. Also, do one directory first to be sure where the error arises. You could even skip the -R if the above command fails to further reduce the variables in play.