reads and overwrites file but writes it in an array