Some people just prefer their own company, or feel anxious and uncomfortable around other people, particularly people they don't know well. That's just their character. This can be common in people with Asperger's Syndrome (which also covers a lot of other characteristics - look it up and see if you recognise any of the traits in yourself).
My own opinion is that it's OK to keep yourself to yourself much of the time if you are happier that way. There's no need to make yourself spend your life surrounded by people if that makes you unhappy. But there is a risk that you could become totally introverted, and become more unable to communicate with other people normally, if you spend all your time on your own. So occasionally you have to take yourself out of your comfort zone, and put yourself in a sociable situation with other people, so you can keep your skills at being sociable.
You do not give your age, or much info, so it would be hard for me to give an answer based on what you have posted, but you seem to have some kind of problem, maybe you would like to talk about it, we are here if you would like to talk luck jo
You experienced a negative relationship with people or someone in particular or a past traumatic experience has resulted in this anti-social behavior.
Also, some people just like to be alone and that's not healty. We need friends, family and a positive environment to grow, but only you know the real reason for this behavior.
Maybe a counselor, therapist of priest (whatever denominations you are from), might be able to help you, become social again. Good luck.