In an OPEN statement with ACTION="write", use POSITION="append" to append data to a file rather than overwriting it. To delete a file that is connected to a unit, CLOSE that unit with STATUS="delete".
ALT program write_append
implicit none
integer, parameter :: iu = 10
character (len=*), parameter :: outfile = "temp.txt"
logical, parameter :: delete_file = .true.
integer :: stat
logical :: exists
open (iu,file=outfile,action="write",status="new")
! status="new" means outfile must not already exist
write (iu,"('a')")
close (iu)
open(iu,file=outfile,action...