Damage and fluctuations induce loops in optimal transport networks