WriteLine[] not working once put into a function

I wrote a function that takes two strings, an integer, and an OutputStream, it's supposed to write to. The function is:

UpdateFile[datum1_String, datum2_String, indexNum_Integer, fileDescr_OutputSteam]:=
Module[{trackingNum},
If[indexNum < 10, trackingNum = "0" <> ToString[indexNum],
trackingNum = ToString[indexNum]]];
WriteLine[fileDescr, trackingNum<>", "<>datum1<>", "<>datum2]]


This doesn't appear to write anything to the text file. The weird thing is, if I just do the following "by hand" (i.e. not make a function and then call it), it does write to the text file.

fileDescr=OpenWrite[StringJoin[{"C:\\Users\\Me\\OutputFiles\\","foo.txt"}]];
indexNum=1;
If[indexNum < 10, trackingNum = "0" <> ToString[indexNum],
trackingNum = ToString[indexNum]]];
datum1="String";
datum2="Another String";
WriteLine[fileDescr, trackingNum<>", "<>datum1<>", "<>datum2]


To try to fix the problem I have:

• Made sure that the parameters I pass in when I call the function have the right head
• Used StringJoin[{trackingNum, ", " , datum1, ", " , datum2}], instead of the shortcut <>
• Cleared the function definition, using Clear[], and redefined it
• Quit and restarted the kernel
• Closed and reopened Mathematica

It seems like some kind of bug or glitch to me, but I'm pretty new to Mathematica in particular, so I'm not sure if this is behavior more experienced users are familiar with. Any suggestions would be greatly appreciated! Thanks, you guys!

• Can you give an example of how you’re calling UpdateFile? – b3m2a1 Jul 25 '19 at 15:40
• @b3m2a1 I am calling it like: UpdateFile["Serial","Tower",1,fileDescr]. Also, I'm not sure if it's clear, but foo.txt is created, it's just blank. – Missyinvisible Jul 25 '19 at 16:32
• The big question is how is the file descriptor call working. And does the function return a result? If it doesn’t you know the call isn’t being structured quite right. – b3m2a1 Jul 25 '19 at 19:27
• I think the call to OpenWrite, that creates the output stream/file descriptor is working fine, since it returns an output stream and I was able to write to it, just not using my UpdateFile[] function. – Missyinvisible Jul 25 '19 at 21:04
• I meant does calling UpdateFile return a result. My guess is you have an issue where it's not being called quite right. – b3m2a1 Jul 25 '19 at 21:05

UpdateFile[fileDescr_OutputSteam, datum1_String, datum2_String, indexNum_Integer]:=