Your problem is that "writeline" sends a return-code (zero), because the operation succeeded. You can get rid of it by doing something like $result=writeline.... or catching the return-code in an IF statement.