Added error control for incarica api call
re-writed the write file procedure