The tilde (~) comparison will not match the actual home directory path. The shell expands ~ to the full home directory path before the comparison, so this check will never match a user's home directory. Use "$TARGET_DIR" == "$HOME" to properly check for the home directory.
if [[ -z "$TARGET_DIR" || "$TARGET_DIR" == "/" || "$TARGET_DIR" == "~" || "$TARGET_DIR" == "$HOME" || "$TARGET_DIR" == "." || "$TARGET_DIR" == ".." ]]; then