Snakes have repeatedly evolved to start spitting as a defensive mechanism against humans. It doesn't serve any purpose in regards to hunting, but is great for scaring humans.