Why Diffusion Models Memorize and How to Mitigate Copying