Added write to file functionality