Added write to file in destructors.