I am working on a paper and I found open-source code that I could use for running a simulation. Should I write my own code for that simulation? Will it be enough if I refer to the code in my citations/references section?
Yes, open-source code can be used for research if it is cited everywhere you use results from it. You may first like to verify that the code is indeed open-source by verifying that the license is one of these: https://opensource.org/licenses
This should be listed clearly on the website/repository/license/readme file. If this is not available, try contacting the author to verify that it is indeed open source.
Certain licenses additionally allow you to freely modify the code for your specific purpose; the link above contains details about this.
Open source software is used everywhere. For all example, nearly all of High Performance Computing, and the entire field of Computational Science and Engineering (CS&E) works with open source software, and does so very successfully. Furthermore, these packages are often at least as good or better than what commercial packages can offer. Many of these packages have been used in hundreds or thousands of papers. A few examples of packages just in my field that have very widely been used is here, here, and here.
So yes, you can use open source software. In particular, there is no reason to believe that open source software just by virtue of being open source is of worse quality.
In practice, nearly every software package has one or more paper that describe its inner workings. The right thing to do when you use a package is to cite these papers.
You'll need to conduct due diligence to ensure that the code generating the simulation is accurate and that you fully understand how it is working; otherwise other peoples' mistakes become your own. Personally, I would take that code and deconstruct it to the point I understand how it works, then re-write it on my own. That said, nothing prevents you from using open source code, just be sure to document accurately and be confident it is doing what you anticipate!