There are two flaws in your script.
First of all, if you
man grep you'll eventually find that:
Normally, exit status is 0 if selected lines are found and 1 otherwise.
What you're seeing is that grep is returning exit status 1 (no lines found) and AppleScript interprets any exit status other than 0 as an error from the shell command.
In theory, grep's '-q' switch should change this behavior, but it doesn't appear to, so the alternative is to use a try block to catch the error:
set isFound to 0
try
set isFound to do shell script "grep -i -c \"test\" /etc/passwd"
end try
if isFound ≠ 0 then
...
end if
However, the second error is that this is likely to return 0 anyway because user accounts are not stored in /etc/passwd as they are on most other Unix systems. Even if they were there, your script would match any user with 'test' in their account entry, including a 'real name' of 'Testing account'.
If your machine is standalone, you're better off querying NetInfo for the username. Either:
do shell script "nicl . -list /users | grep -i \"test$\""
(with the same caveats as above when dealing with a non-0 exit status) or, even better, query the user account directly:
set userAccount to "Invalid User"
try
set userAccount to do shell script "nicl . -read /users/test"
end try
if userAccount ≠ "Invalid User" then
-- user exists
end if