send $index in echo to file rather than write