The evolution of writhe in kink-unstable flux ropes and erupting filaments