You primality test is probabilistic and its probability of giving correct result is even smaller because of small number of iterations of fermat test.
Its giving wrong result for 3, 5. You need to test it properly ( i hope you fully understand how fermat primality test works ).