title: Saving elements of RDD in Spark application
body: <p>I am running spark application on a cluster. I want perform some operation on each of the elements in RDD and save each element into a textfile. </p>
  
  <p>I am calling <code>foreach</code> on myRDD</p>
  
  <pre class="lang-py prettyprint-override"><code>  myRDD.foreach(process)
  
     def process(elements):
          // some operation that extracts the strings
          // and converts to myList
          myList = ... 
  
          with open("somefile.txt", "a+") as myfile:
              print "----SAVED----"
              myfile.writelines(myList)
  </code></pre>
  
  <p>However, i am not able to find the somefile.txt even though I do find that the print statement gets printed without any errors/warning.  Where is somefile.txt saved? If my methods is incorrect, how do i save individual elements of RDD?</p>