It's a way to flirt.
Teasing communicates effectively:
* I'm not a threat to you, being around me is safe.
* I have humour
* I am fun to be around
As the other commenter said, it creates bonding. You only tease people you like. I can't think of a faster way to demonstrate these qualities, which are perceived as very attractive.