Scarring is a normal part of the healing process. When body tissue is wounded, scar tissue will replace the tissue that was there before. Wounds can be created purposefully, such as during surgery, or by accident (falling and scraping your knee). In the majority of cases, a scar will form in replace of a wound.
When undergoing surgery, your doctor will take care to ensure scarring is minimal. However, in some cases this won’t be possible - particulary in larger surgical procedures or in an emergency setting.