diff --git a/download-latest-firmware-build.py b/download-latest-firmware-build.py
index c56a8ddbabada6e2683dee70b0ac5d74d9cf2cc7..5432cf34bd03faf45cc55bab6a66df5ec2560df3 100755
--- a/download-latest-firmware-build.py
+++ b/download-latest-firmware-build.py
@@ -16,7 +16,7 @@ PROJECT_ID = 1
 
 ap = argparse.ArgumentParser()
 ap.add_argument("--pipeline-id", help="Pipeline ID to download. If omitted, download latest successfull.", default=None)
-ap.add_argument("--pipeline-id-file", help="Store downloaded Pipeline ID in this file and only download if latest pipeline ID doesn't match file contents", type=argparse.FileType("r+"))
+ap.add_argument("--pipeline-id-file", help="Store downloaded Pipeline ID in this file and only download if latest pipeline ID doesn't match file contents")
 args = ap.parse_args()
 
 def find_version_from_archive(archive_file_list):
@@ -52,11 +52,13 @@ if args.pipeline_id is None:
     pipeline_id = find_latest_pipeline_id()
 
     if args.pipeline_id_file:
-        pipeline_id_file = args.pipeline_id_file.read()
-
-        if pipeline_id == args.pipeline_id_file:
-            print("Pipeline up to date")
-            sys.exit(1)
+        try:
+            with open(args.pipeline_id_file, "r") as pipeline_id_file:
+                if pipeline_id == pipeline_id_file.read():
+                    print("Pipeline up to date")
+                    sys.exit(1)
+        except FileNotFoundError:
+            pass
 else:
     pipeline_id = args.pipeline_id
    
@@ -79,8 +81,8 @@ for job in pipeline_jobs:
                     artifact_zip.extractall("gluon/output/")
                     os.rename("gluon/output", version)
                     if args.pipeline_id_file:
-                        args.pipeline_id_file.truncate(0)
-                        args.pipeline_id_file.write(pipeline_id)
+                        with open(args.pipeline_id_file, "w") as pipeline_id_file:
+                            pipeline_id_file.write(str(pipeline_id))
                 else:
                     print(f"'{version}' already exists")
                     sys.exit(1)