Goosebumps are basically an old biological mechanism that made much more sense when our ancestors had considerably more body hair.
One of the reasons is that when our ancestors were cold, they got goosebumps. It helped air to be trapped between their hair, and it trapped heat inside the body.
The second reason is fear. When people saw something scary, they got goosebumps – their hair stood up, so it made them look bigger.