Seems that the bash wrapper only calls python (+ some post processing). In my opinion you don’t need this bash wrapper script but you should code is directly in the tool’s command block.
Like @gbbio I would suggest that you should modify the python script (assuming its your code), to just output to a configurable directory, e.g python mytool.py --input $input --output output. The reason is that a central directory like /results/output-tools/MYTOOL/sessions/ (in your example) does not exist on other systems and complicates installation.
But I completely disagree that tempfolder=$(mktemp -d /galaxy/galaxy/database/files/XXXXXX) is a good idea. First of all /galaxy/galaxy/database/files/ might not exist on all systems and more importantly database/files/ is the central location of Galaxys files, one is not supposed to write into this. Also the directory is writable only by the Galaxy system user, i.e. writing won’t work if Galaxy runs jobs as real user.
The solution is simple. Each Galaxy job already runs in its own temporary directory (called job working directory). So just create a temporary directory (e.g. mkdir outdir) in the current working dir. and use this. Galaxy will take care of cleanup after the job finished.
So the command block could look something like:`
mkdir outdir
python $__tool_directory__/mytool.py --input '$input' --output outdir &&
output_dir/file1.txt '$file1' &&
output_dir/file2.txt '$file2'
Note the use of && which ensures that all commands must be successful.
Instead of copying the output files you might also use the from_work_dir attribute of the <data> tag.