update write function to write an imploded array into a string