Why do you need the .tmp-file? You could write the output directly to $TARGET.