well but with \unexpanded the filler is also considered while looking for {, same thing. The difference is that in the case of \unexpanded the relax is immediately thrown away so it doesn't take part in the \if comparison, while with \write the \relax stays and so TeX hits \fi twice and then determines that the if is \true. With tracing you get {\immediate}
{\if}
{\fi}
{\fi}
{true}
{\fi}