I suspect you do not want to do a 3drefit, but instead use 3dresample. 3drefit modifies the header without changing the dataset and without regard to the original orientation. 3dresample, instead, resamples the dataset to a new grid. Here is a new script that does something similar to what you have asked.
3dresample -orient RAI -prefix rest_RAI -inset rest+orig
3dDetrend -del 2 -expr \"Pleg(1,(t-$NT)/$NT)\" -prefix rest_3d rest_RAI+orig.
@auto_tlrc -base TT_avg152T1+tlrc -input anat+orig -no_ss -suffix NONE -dxyz 1
@auto_tlrc -apar anat+tlrc. -dxyz 3 -suffix NONE -input rest_3d+orig
or in place of the last line, you could align the rest_3d+orig dataset to the anatomical and anatomical talairach dataset with -
align_epi_anat.py -anat anat+orig -epi rest_3d+orig -base 4 -tlrc_apar anat+tlrc \
-epi2anat -suffix _al2anat
Also, you have probably realized only jpeg images can be attached to the message board postings and not datasets.