Factors to do with their environment, if their parents are pessimistic they are more likely to take the same attitude.
Pessimism isn't always a bad thing, if you are in a situation where it pays to be risk averse then a bit of pessimism can help you take a wiser decision. When you've drunk 4 pints and are considering whether to drive your car then you don't want to be thinking well look on the bright side, I might not get stopped by the police and I will probably get home fine.
Also in business if you have creative people and risk takers you need some more pessmistic types involved in your risk management.
The psychology literature on this says the main areas in which pessimism is harmful (eg in terms of career success, health outcomes and so on) is in terms of how optimistic or pessimistic your explanatory style is of explaining events that happen to you. Explanatory style means how much you personalise an event (make it your fault/responsibility), how much you think it has permanent and lasting consequences, and how pervasive you think it is (ie if something goes wrong do you just compartmentalise it to that thing or do you think it has implications for other aspects of your life).
Eg say you fancy someone and are deciding to ask them out. An optimist thinks they will say yes, a pessimist thinks they will say no. Pessimism isn't going to change the outcome although the pessimist has a lower chance because of the possibility that they won't ask the person out in the first place.
But the real difference in consequences comes in whether the explanatory style is more optimistic or more pessimistic.
So someone with pessimistic explanatory style would think: "she turned me down, this is because I'm not good enough, I'm never going to be good enough for a girl, this girl rejecting me means that pretty much every girl will reject me"
Someone with optimistic explanatory style would think "she turned me down, I mustn't have been her type, ah well that's her chalked off, I will never ask her out again so there's no reason being rejected by her would have any implications for anyone else I asked out. It doesn't change my self-image about how good I am at anything else in my life."
The pessimistic explanatory style person is likely to run in to more problems with depression and illness and also have lower life success because they tend to quit early when they run in to problems and also this type of person tends to find that one bad experience tends to lead to a run of bad events as they spiral down.
Someone with optimistic explanatory style avoids these type of problems because although they are as much exposed to bad luck as anyone else, when they have bad events they tend to be isolated and not have impacts on other parts of their lives.
If you look for literature on stuff like learned optimism, explanatory style you can read more about this, it's been quite well studied in psychology and in cognitive behavioural therapy it's one of the things professionals will work on as part of treatment, to change the patient's explanatory style.