South West Water has agreed to pay a £24m penalty for wastewater spillages, the water regulator said.