When using `mktemp` as outlined above replace this with `rm -- "$cookies_file"`.  And for more robustness put this line in a `trap`.