Fix usage of write!() to avoid ICE in latest rustc nightly

With recent changes, `write!(w, ...)` no longer works and should be
replaced with `write!(&mut w, ...)`. Unfortunately, this is slightly
obscured because it also ICE's. Fix the few cases where we weren't using
`&mut w` so it compiles properly.