I've written a small bash script to help with updating various packages/dependencies on my machine (Pop!_OS) but it doesn't seem to be working correctly for flatpak. If I run flatpak update in the terminal it will show that I have updates, but when running the script there aren't any updates.

The Script:

#!/bin/bash

# Update package list
sudo apt update -y

# Upgrade the packages and dependencies
sudo apt upgrade -y

# Remove unnecessary packages and dependencies
sudo apt autoremove -y

# Clean package cache
sudo apt clean -y

# Update Flatpak
sudo flatpak update -y

# Update firmware
sudo fwupdmgr update -y

echo "All updates and upgrades have completed sucessfully!"

EDIT: Running flatpak update -y without sudo fixes the issue.