It looks like the code comes from Steve Purcell's emacs.d.
He actually updated it to use cl-lib now, so you can try his more recent version:
(defun sanityinc/add-subdirs-to-load-path (parent-dir)
"Add every non-hidden subdir of PARENT-DIR to `load-path'."
(let ((default-directory parent-dir))
Just remove the first line, which loads the cl package, and then fix any errors that result.
In particular, functions like remove-if-not are now called cl-remove-if-not, and are always available (technically they are autoloaded). The cl package just adds an alias for it called remove-if-not to allow older code to still work.
As discussed in the comments to my question, I was a bit confused when writing the question, but will keep the original text in case similarly inexperienced people approach it from the same way.
To answer the main question "How to dynamically replace certain text, by evaluating a function on change in current buffer", below is an example of how to ...
I am using dracula-theme (load-theme 'dracula t), which was the main cause of the error I was facing.
When I use query-replace-region-or-from-top function along with dracula-theme and (setq-default frame-background-mode 'dark) I was facing the error I mention on my question.
(defun query-replace-region-or-from-top () ... ;; function from my question