I don't have time actually experiment with this, but
experience with shell scripting tells me that this
part would never work. You don't cat a variable,
which is stored in memory and not as a file.
You have it mixed up.
FROM=test.fil; export FROM; cat $FROM
will cat the file
| echo $FROM > temp.txt
might work.
FROM=test.fil; export FROM; echo $FROM
will print 'test.fil'
-Steve