The memory needed to store a big matrix can easily get out of hand, which is why nx.adjacency_matrix(G) returns a "sparse matrix" which is stored more efficiently (exploiting that many entries will be 0).
Since your graph has 131000 vertices, the whole adjacency matrix will use around 131000^2 * 24 bytes(an integer takes 24 bytes of memory in python), which is about 400GB. However, your graph has less than 0.01% of all edges, in other words it is very sparse and sparse matrices will work for you.
In order to get the sparse matrix, just use A = nx.adjacency_matrix(G) without calling A.todense() after it (this tries to store it normally again).
There is an inbuild function of scipy.sparse to efficiently save and load sparse matrices, see here. For example, to save your sparse matrix A, use
scipy.sparse.save_npz('filename.npz', A)
If it is important for you to use txt or CSV, you will have to do it manually. This can be done by iterating through every row of your matrix and writing these one by one to your file:
for i in range(A.shape[0]):
row = A.getrow(i).todense()
[write row to file using your preferred method]
This might take a few minutes to run, but should work (I tested with a path of the same size).
nxthe networkx library? If so, what doeslen(G.nodes())print, i.e. how many nodes are in the graph? Also what islen(G.edges())? Also which line of your code above gives the error? Theadjacency_matrix()call, or thetodense()call?