This is what you wanted to happen:
- The script runs and output things
- The script runs a command in the background
- The script exits
- The pipe closes
tee
exits
This is what's happening:
- The script runs and outputs things
- The script runs a command in the background, with the pipe as stderr
- The script exits
- The pipe is still held open by the backgrounded command
tee
never exits.
You fixed it by pointing stderr to the log file rather than the pipe, so that the backgrounded process no longer keeps the pipe open.
The meaning of the order of 2>&1
and the redirect has been explained in other answers, and shellcheck would have automatically pointed out this problem in your code.