Unintuitive debug/3 - format/2 interaction

It is indeed about the streams. debug/3 writes to user_error, format/2 to current_output, which is normally user_output. user_error is unbuffered, while user_output is line buffered (when talking to a terminal; fully buffered otherwise). So, the debug/3 write immediately. the baz is buffered until the ~n. To get what you want, use flush_output/1 or change user_output to be unbuffered using set_stream/2.