cURL in bash script reads $HOME as /root/

OS in question is Fedora 40.

I would like to create a directory and download a file to it, so I wrote this simple script

#!/bin/bash

set -eu -o pipefail 

sudo -n true
test $? -eq 0 || exit 1

curlpackages="$HOME/curl-packages"
mkdir -p $curlpackages
curl --output-dir $curlpackages -JLO <someaddress>

I would expect the directory and file to be under /home/myname/ but instead I get /root/ . Is this because I run this with sudo? If so, can I use another variable instead of $HOME to point to my home folder instead of root?