Greetings @Svetoslav,
What permissions does your SD card have? I assume this code is being executed as the “torizon” user. If your SD card requires root user permissions, then it would make sense that this fails. If your SD/USB driver is FAT formatted (which most are by default) then it gets auto-mounted with root user permissions.
You would need to re-mount your driver with proper permissions such that the “torizon” user can work with it. One method is detailed in this thread: R/W access permissions to torizon user/containers on auto-mounted USB drive
Best Regards,
Jeremias