Origin of sawtooth domain walls in ferroelectrics