Writing to standard output and writing to a file are two different things, so you will always need separate instructions. But you do not need to open and close the file for every line you write.
Honestly, I don’t think it is much more effort:
open(unit=10, file='result.txt', status='replace', form='formatted')
....
write( *, *) "Here comes the data"
write(10, *) "Here comes the data"
....
write( *, *) root1, root2
write(10, *) root1, root2
....
close(10)
, .
, , , :
Linux Unix ( MacOS), , , , :
$ ./my_program | tee result.txt
result.txt
"" :
$ ./my_program &
$ tail -f result.txt
: , , :
program my_program
implicit none
real :: root1, root2, root3
....
open(10, 'result.txt', status='replace', form='formatted')
....
call write_output((/ root1, root2 /))
....
call write_output((/ root1, root2, root3 /))
....
call write_output((/ root1, root2 /))
....
close(10)
....
contains
subroutine write_output(a)
real, dimension(:), intent(in) :: a
write( *, *) a
write(10, *) a
end subroutine write_output
end program my_program
, , , . , real, (integer, character ..) write " " .