The short answer is evolution. Shouting may accomplish two things when startled. First, whatever startled you may be startled itself by your screaming reaction and either run off or is at least taken back to present an opprotunity for you to escape. But more realistically, it serves as a means of notifying others that you are in distress and in need of aid or to avoid/ cautiously approach this area as there is a threat to you as well.