Adding website to block via /etc/hosts not working

I found this on GitHub but I haven't tried it.

# Simply curl -s this and pipe it into sh.
# This script uses root privileges, be careful!
# Appends a list of known Reddit subdomains to your /etc/hosts file, and points them to localhost.
# Should work totally fine, but I take no responsibility if it messes up your machine.

# **Made by Colby Ludwig** (twitter.com/cdl)

sudo bash -c "echo -e '\n\n# -- Block all of Reddit --\n127.0.0.1\t\treddit.com\n127.0.0.1\t\twww.reddit.com\n127.0.0.1\t\tnp.reddit.com\n127.0.0.1\t\tssl.reddit.com\n127.0.0.1\t\tblog.reddit.com\n127.0.0.1\t\tfr.reddit.com\n127.0.0.1\t\tpay.reddit.com\n127.0.0.1\t\tes.reddit.com\n127.0.0.1\t\tenus.reddit.com\n127.0.0.1\t\ten.reddit.com\n127.0.0.1\t\tru.reddit.com\n127.0.0.1\t\tus.reddit.com\n127.0.0.1\t\tde.reddit.com\n127.0.0.1\t\tdd.reddit.com\n127.0.0.1\t\tno.reddit.com\n127.0.0.1\t\tpt.reddit.com\n127.0.0.1\t\tww.reddit.com\n127.0.0.1\t\tss.reddit.com\n127.0.0.1\t\t4x.reddit.com\n127.0.0.1\t\tsv.reddit.com\n127.0.0.1\t\tnl.reddit.com\n127.0.0.1\t\thw.reddit.com\n127.0.0.1\t\thr.reddit.com' >> /etc/hosts"

Safari keeps its own ephemeral DNS cache. If you've just added the record to /etc/hosts, try quitting Safari, running dscacheutil -flushcache and restarting the computer.