After discussing with Adrien, I moved all my files from the /home to the /scratch folder and redid all the analysis after changing all the paths and everything seems to have worked this time. It seems that the issue was coming from the fact that the analysis was saturating the allowed space in the home folder (1To) and my script was crashing whenever that limit was reached (hence the apparent random timing of when it was crashing).