There are many ways to have your program decide where to write its output, but as far as I know, they all require two separate write statements, one for the integer file unit and the other for the output character string. It could be two separate subroutines, or one subroutine with some kind of internal logic to decide which of the write statements are executed, but I think all of the solutions will eventually require two write statements.
A similar issue arises when you want to write the same output to more than one unit. However, in this case the programmer can put the unit numbers in an array and loop over the elements of the array as the output unit while using only a single write statement.
Finally I would caution against using a function to do i/o, use a subroutine instead. The reason is that it is easy to inadvertently nest i/o statements within such functions, which is not allowed in fortran (with a few exceptions). Debugging such code can be difficult.