Added write to file method