Directory .../Serializer not writable, please chmod to 777 in ../Serializer.php

Hello, I am getting these errors in my error_log every time I try to access pages where it uses htmlpurifier.

Directory /var/www/html/classes/library/HTMLPurifier/DefinitionCache/Serializer not writable, please chmod to 777 in /var/www/html/classes/library/HTMLPurifier/DefinitionCache/Serializer.php on line 292

What exactly is the purpose of this file, and I've read other places that it's bad practice to chmod to 777.

It's a cache for a large pile of helper data structures which HTML Purifier needs to do its work. In principle, you could avoid having HTML Purifier ever writing to this directory by making sure the cache files you need are always present, but in practice this is pretty annoying and no one does it.

It's not necessary to 777 the folder; any permissions for which the server running PHP has write access to the directory will do.