<p>Please help, I am stuck here ---</p>

<pre><code>irb&gt; a = "line of text\n  line two\n  line three"
irb&gt; system("cat &gt; test_file &lt;&lt; #{a}")
cat: of: No such file or directory
cat: text: No such file or directory
=&gt; false
</code></pre>

You need to quote the interpolated parameter:
```
```
system("cat > test_file << \"#{a}\"")
```
```
And, cat is expecting a filename, not some text to append to test_file, so, this would work as I think you intended:
```
```
system("echo \"#{a}\" >> test_file")
```
```
If you want to do this in pure Ruby let me know and I'll give you an example.