When ESRI grid file format rasters are read into for loop and convert them to HFA files, output file name is not set as same as the input file name. Following code is used for the conversion;
library(raster)
raster_data <- list.files(pattern='rain', full.names=FALSE)
# "rain1970" "rain1971"
for (i in 1:length(raster_data)) {
r.nc <- raster(raster_data[i])
writeRaster(r.nc, paste0(i, '.IMG', sep = ''), format = 'HFA', overwrite = T)
}