Fix attempt to write to directory