Problem with scripted account deletion syntax
[ (and [[) expect an expression, not a command; so you can't directly run commands inside a test.

When you put a pipe in your condition it terminates the evaluation started with [ which makes ] to be treated as an argument to the last grep.

Try putting your condition inside $() like so:

if [ $(dscl . -list /Users | grep -v '^_' | grep $USERNAME) ];


That way the expression (including all the pipes) is going to be executed first and return its exit code to be used in your evaluation.